iphone - SLRequest 适用于模拟器而非设备

标签 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.)"}

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

最佳答案

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

this .

关于iphone - SLRequest 适用于模拟器而非设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12875294/

相关文章:

ios - 更改删除按钮的 View

ios - 如何从我的 iOS 应用程序中删除 crashlytics?

ios - 如何在 iOS 中使用 Twitter API 1.1 获取 Token

html - 删除 Twitter 小部件周围的边框

iphone - Dropbox 显示文件修改日期

ios - 将位置源从 GPS 切换到本地 `gpx` 文件

iphone - 在iPhone上播放midi文件

ios - 条件绑定(bind)中的绑定(bind)值必须是可选类型 [IOS - SWIFT]

ios - ERROR ITMS-9000 : "This bundle is invalid. IPA 格式需要一个名为 Payload 的顶级目录,仅包含一个 .app 包和可选的

ios - 更新到 iOS 9 错误 : i386 Unsupported architecture