简体   繁体   中英

SLRequest works on simulator not on device

I'm using SLRequest to post to a user's Twitter stream, and the following code works in the simulator to post, but not on the actual device.

//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];

When I run this code on the simulator, everything works properly, and the text gets posted to the appropriate Twitter account; however, when it runs on the actual device (with the same account set up), I get the following error message (no error is produced in the simulator):

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

Has anyone else encountered this error before? I've been searching for days, but have yet to find any solution online. Any information or help would be much appreciated!

You use the wrong url and parameters.

Look at this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM