2010-09-26 71 views
1

我已經在我的應用程序中實現了MGTwitterEngine,它的工作接近完美。iPhone遇到Twitter實現收到NSURLErrorDomain錯誤

第一個「奇怪」的事情時,我推在Twitter的形式是的UIViewController是happends,我收到這在控制檯:

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; 

} 

回答

3

根據Foundation constants reference, NSURLErrorDomain -1012是NSURLErrorUserCancelledAuthentication

當用於認證的異步請求被用戶取消返回。 這通常是通過單擊用戶名/密碼對話框中的「取消」按鈕而發生的,而不是用戶嘗試進行身份驗證。

+0

好的。但我按下了「發送推文」按鈕。我沒有取消按鈕。 – 2010-09-26 17:24:43

+0

某處某處取消了某些內容。發生這種情況,以及這是否是一個問題,是由你來找出。 – 2010-09-26 22:10:59

+0

我通過重新安排委託方法調用來解決它。像這樣:http://pastie.org/1186411 – 2010-09-28 13:01:52