iPhone 与 Twitter 实现收到 NSURLErrorDomain 错误

发布于 2024-09-25 10:29:46 字数 2587 浏览 1 评论 0原文

我已经在我的应用程序中实现了 MGTwitterEngine,它的工作近乎完美。

当我将 UIViewController 推送到 Twitter 表单所在的位置时,发生的第一个“奇怪”的事情是,我在控制台中收到此消息:

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

我应该隐藏登录表单还是您的建议是什么?

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

- (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 消息已发布。但我还是收到了该错误消息。

我查看了 Twitter 控制面板中的应用程序设置。访问类型“读和写”。

有人熟悉这个问题吗?

我实现的委托方法如下:

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

}

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;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-10-02 10:29:46

根据 基础常量参考,
NSURLErrorDomain -1012 是 NSURLErrorUserCancelledAuthentication :

当用户取消异步身份验证请求时返回。
这通常是通过单击用户名/密码对话框中的“取消”按钮引起的,而不是用户尝试进行身份验证。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文