2010-07-26 124 views
1

過去幾天我一直試圖讓Twitter的OAuth工作在我的iPhone應用程序上,而且我不能爲我的生活弄清楚爲什麼我得到這個錯誤。我已經改變了一段時間以來的方式,但仍然一無所獲。所以我轉而希望弄清楚。「無法識別的選擇器」錯誤。無法弄清楚

本教程是linked here。下載應用程序並運行它非常有效。它不適合我。

這是我得到的錯誤 -

2010-07-25 20:04:52.224 AppTest[4620:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OAToken setVerifier:]: unrecognized selector sent to instance 0x6c2acc0' 

誰能告訴我什麼,我做錯了什麼?我使用幾乎相同的代碼。

編輯:下面的代碼,我使用setVerifier:

- (IBAction)finishSetup:(id)sender { 

     NSString *thePin = [[NSString alloc] initWithString:pinText.text]; 
     NSLog(@"%@", thePin); 
     if([thePin length] == 7 && [[NSScanner scannerWithString:thePin] scanInt:NULL]) { 

      loadingView.hidden = NO; 

      [pinText resignFirstResponder]; 

      OAConsumer *consumer = [[OAConsumer alloc] initWithKey:consumer_key secret:consumer_secret]; 
      OADataFetcher *fetcher = [[OADataFetcher alloc] init]; 
      NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"]; 

      [accessToken setVerifier:pinText.text]; 

      NSLog(@"Using PIN %@", accessToken.verifier); 
      OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url consumer:consumer token:accessToken realm:nil signatureProvider:nil]; 
      [request setHTTPMethod:@"POST"]; 

      NSLog(@"Getting access token..."); 

      [fetcher fetchDataWithRequest:request delegate:self didFinishSelector:@selector(accessTokenTicket:didFinishWithData:) didFailSelector:@selector(accessTokenTicket:didFailWithError:)]; 

     } else { 

      loadingView.hidden = YES; 
      error_alert = [[UIAlertView alloc] initWithTitle:@"TestApp" message:@"The PIN you have entered is invalid. Please try again." delegate:self cancelButtonTitle:@"Cancel Login" otherButtonTitles:@"Try again", nil]; 
      [error_alert show]; 
      [error_alert release]; 

     } 

     [thePin release]; 

    } 
+0

「幾乎使用相同的代碼」與「使用相同的代碼」不一樣。如果不同,請將其發佈在您的問題中。 – 2010-07-26 00:23:19

+0

這是相同的代碼,我的道歉。唯一的區別是該教程不適用於iPhone,而是使用Objective-C和Cocoa。 – 2010-07-26 00:31:51

+0

您應該在您使用' - [OAToken setVerifier:]' – kubi 2010-07-26 00:35:24

回答

0

如果這樣做,新的XCode 4是驚人的。我在鏈接的教程中下載了ZIP文件,看起來好像OAMutableURLRequest.m在整個文件中都有錯誤,認爲NSString響應URLEncodedString。

嘗試更新URLEncodedString到

stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding 

讓我知道你的作品!

+0

默認情況下,所有XCode4都會打開靜態分析。您可以通過執行「構建和分析」來獲取舊XCode中的相同信息 – 2010-07-26 01:48:10

0

嘗試

[accessToken setVerifier:thePin]; 
0

我認爲BarrettJ有它。 setVerifier參數需要一個NSString。由於您提供了其他內容,因此它會查找與簽名匹配的不同setVerifier,並且找不到它。這將導致「無法識別的選擇器」錯誤。

1

的accessToken setVerifier:期待一個NSString *

thePin和pinText.text都的NSString *

真的需要出示你實例中的accessToken變量。

1

我是從這裏鏈接的帖子的作者。

您收到此錯誤的原因是因爲您使用的OAuthConsumer版本錯誤。有幾個版本可用,其中大多數版本都沒有OAToken中的「驗證器」字段,並且會返回如果您嘗試使用它的錯誤。我的帖子中的示例項目包含正確的OAuthVerifier版本,這就是它工作的原因。

我使用僅包含OAuthConsumer的ZIP文件更新了我的帖子。你可以在你的項目中使用它,它會工作。當然,您也可以只複製示例項目中的OAuthConsumer文件並在您的文件中使用,它也可以工作。

+0

我相信另一種選擇是進行如下調用:[請求setOAuthParameterName:@「oauth_verifier」withValue:oauthVerifierString] – 2012-02-10 11:18:20

0

在建添加-all_load標誌設置

https://developer.apple.com/library/mac/#qa/qa2006/qa1490.html

-all_load強制鏈接從每一個存檔看到,即使是那些沒有Objective-C代碼加載所有的目標文件。 -force_load可在Xcode 3.2及以後。它允許更精細的穀物控制歸檔加載。每個-force_load選項後面都必須有一個到存檔的路徑,並且該存檔中的每個目標文件都將被加載。