SLRequest适用于不在设备上的模拟器

时间:2012-10-13 17:42:01

标签: iphone ios twitter ios6

我正在使用SLRequest发布到用户的Twitter流,并且以下代码在模拟器中工作以发布,但不在实际设备上。

//create the SLRequest and post to the account

//create the NSURL for the Twitter endpoint
NSURL *profileURL = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"];

//Create the dictionary of parameters that contains the text to be posted               
NSDictionary *parameters = [NSDictionary dictionaryWithObject:[messageTextView text] forKey:@"status"];

//create the SLRequest         
SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:profileURL parameters:parameters];

//assign the twitter account for posting   
twitterRequest.account = [_twitterAccounts objectAtIndex:i];

if(!CGSizeEqualToSize(imageView.image.size, CGSizeZero))
{
    //multipart data with image
    [twitterRequest addMultipartData:UIImageJPEGRepresentation(imageView.image, 0.7) withName:@"media" type:@"image/jpg" filename:@"image001.jpg"];
}

SLRequestHandler requestHandler = ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
{
    if(error)
    {
        NSLog(@"%@", error);
    }
};

//perform the request          
[twitterRequest performRequestWithHandler:requestHandler];

当我在模拟器上运行此代码时,一切正常,文本会发布到相应的Twitter帐户;但是,当它在实际设备上运行时(设置相同的帐户),我收到以下错误消息(在模拟器中没有产生错误):

2012-10-13 13:39:32.967 Status App[10684:1803] Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x1d9f37f0 {NSErrorFailingURLKey=https://api.twitter.com/1/statuses/update.json, NSErrorFailingURLStringKey=https://api.twitter.com/1/statuses/update.json, NSUnderlyingError=0x1d9f35c0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"}

之前有没有其他人遇到此错误?我一直在寻找几天,但还没有在网上找到任何解决方案。任何信息或帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

您使用了错误的网址和参数。

请看this