iPhone meets Twitter implementation recieves NSURLErrorDomain error

て烟熏妆下的殇ゞ 提交于 2019-12-13 00:11:17

问题


I have implemented MGTwitterEngine in my application and it works near to perfect.

The first "weird" thing that happends when I push the UIViewController where the Twitter form is, I recieve this in the Console:

This app was previously authorized for a Twitter account so you can press the second button to send a tweet now.

Should I hide the login form or what is your recommendation?

The second "weird" thing that happends is when I the press the "Send tweet"-button it works and the message is posted on Twitter. But, I recieve an error message in the method:

- (void) twitterXAuthConnectionDidFailWithError: (NSError *)error;

And the error message is:

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0xde3edf0 {NSErrorFailingURLKey=https://api.twitter.com/oauth/access_token, NSErrorFailingURLStringKey=https://api.twitter.com/oauth/access_token, NSUnderlyingError=0xde430c0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"}

Which I find strange, because the twitter message is posted. But I recieve that error message anyway.

I have looked into the application settings in the Twitter control panel. The access type is "Read & Write".

Anyone familiar with this problem?

The delegate methods i've implemented are these:

#pragma mark XAuthTwitterEngineDelegate methods

- (void) storeCachedTwitterXAuthAccessTokenString: (NSString *)tokenString forUsername:(NSString *)username
{
    NSLog(@"Access token string returned: %@", tokenString);

    [[NSUserDefaults standardUserDefaults] setObject:tokenString forKey:kCachedXAuthAccessTokenStringKey];

    // Enable the send tweet button.
    [loadingIndicator stopAnimating];
    self.sendTweetButton.enabled = YES;
}

- (NSString *) cachedTwitterXAuthAccessTokenStringForUsername: (NSString *)username;
{
    NSString *accessTokenString = [[NSUserDefaults standardUserDefaults] objectForKey:kCachedXAuthAccessTokenStringKey];

    NSLog(@"About to return access token string: %@", accessTokenString);

    return accessTokenString;
}


- (void) twitterXAuthConnectionDidFailWithError: (NSError *)error;
{
    NSLog(@"Error: %@", error);

    [loadingIndicator stopAnimating];
    self.sendTweetButton.enabled = TRUE;
}


#pragma mark -
#pragma mark MGTwitterEngineDelegate methods

- (void)requestSucceeded:(NSString *)connectionIdentifier
{
    UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"Sent!" 
                          message:@"The tweet is sent!" 
                          delegate:self 
                          cancelButtonTitle:nil 
                          otherButtonTitles:@"Okay", nil];
    [alert setTag:0];
    [alert show];
    [alert release];

    [loadingIndicator stopAnimating];
self.sendTweetButton.enabled = TRUE;

}

回答1:


According to Foundation constants reference, NSURLErrorDomain -1012 is NSURLErrorUserCancelledAuthentication:

Returned when an asynchronous request for authentication is cancelled by the user. This is typically incurred by clicking a “Cancel” button in a username/password dialog, rather than the user making an attempt to authenticate.



来源:https://stackoverflow.com/questions/3798494/iphone-meets-twitter-implementation-recieves-nsurlerrordomain-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!