iPhone符合Twitter实施,收到NSURLErrorDomain错误 [英] iPhone meets Twitter implementation recieves NSURLErrorDomain error

查看:139
本文介绍了iPhone符合Twitter实施,收到NSURLErrorDomain错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中实现了MGTwitterEngine,并且它的运行接近完美.

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

当我将UIViewController推到Twitter表单所在的位置时,发生的第一个怪异"事情是在控制台中收到的:

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?

发生的第二个奇怪"的事情是,当我按下发送推文"按钮时,它起作用了,并且消息被发布到了Twitter上. 但是,我在该方法中收到一条错误消息:

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;

错误消息是:

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

我发现这很奇怪,因为发布了twitter消息.但是我仍然收到该错误消息.

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

我已经在Twitter控制面板中查看了应用程序设置.访问类型读与写".

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

有人熟悉这个问题吗?

我实现的委托方法是:

#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;

}

推荐答案

根据

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.

这篇关于iPhone符合Twitter实施,收到NSURLErrorDomain错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆