我正在使用 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.)"}
以前有没有其他人遇到过这个错误?我一直在寻找几天,但还没有在网上找到任何解决方案。任何信息或帮助将不胜感激!