【问题标题】:SLRequest works on simulator not on deviceSLRequest 适用于模拟器而不是设备
【发布时间】:2012-10-04 05:26:47
【问题描述】:

我正在使用 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.)"}

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

【问题讨论】:

    标签: iphone ios twitter ios6


    【解决方案1】:

    你使用了错误的url和参数。

    this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 2011-03-08
      • 2015-02-13
      相关资源
      最近更新 更多