1
我正在使用SLRequest發佈到用戶的Twitter流,以下代碼在模擬器中工作以發佈,但不在實際設備上。SLRequest在模擬器上工作不在設備上
//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.)"}
有沒有其他人遇到過這個錯誤?我一直在尋找幾天,但還沒有找到任何解決方案。任何信息或幫助將不勝感激!