我正在使用 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.)"}
有没有其他人遇到过这个错误?我一直在寻找几天,但尚未在网上找到任何解决方案。任何信息或帮助将不胜感激!
最佳答案
您使用了错误的 url 和参数。
看this .
关于iphone - SLRequest 适用于模拟器而非设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12875294/