2012-05-18 30 views
7

Tôi đã thêm thành công SA_OAuthTwitterEngine vào ứng dụng của mình nhưng tôi gặp phải một vấn đề rất lạ. Khi tôi đăng nhập vào Twitter, ứng dụng của tôi sẽ gặp sự cố sau:Công cụ Twitter SA_OAuthTwitterEngine tích hợp?

- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username 
{ 
    [_engine sendUpdate:[NSString stringWithFormat:@"This Tweet for testing!"]]; 
    NSLog(@"Authenicated for %@", username); 
} 

Ứng dụng gặp sự cố trên [_engine sendUpdate:[NSString stringWithFormat:@"This Tweet for testing!"]];. Nếu tôi sử dụng [_engine sendUpdate:nil]; thay vào đó thì nó sẽ hoạt động mà không bị lỗi nhưng không thể gửi tweet từ tài khoản của tôi.

Khi tôi đang cố gắng để theo dõi trên sendUpdate phương pháp sau đó tôi đã nhận vấn đề thực tế trên [theRequest prepare]; tuyên bố trong hàm sau,

- (NSString *)_sendRequestWithMethod:(NSString *)method path:(NSString *)path queryParameters:(NSDictionary *)params body:(NSString *)body requestType:(MGTwitterRequestType)requestType responseType:(MGTwitterResponseType)responseType 
{ 
    NSString *fullPath = path; 
    NSString *urlString = [NSString stringWithFormat:@"%@://%@/%@", (_secureConnection) ? @"https" : @"http", _APIDomain, fullPath]; 
    NSURL *finalURL = [NSURL URLWithString:urlString]; 
    if (!finalURL) { 
     return nil; 
    } 
OAMutableURLRequest *theRequest = [[OAMutableURLRequest alloc] initWithURL:finalURL consumer:self.consumer token:_accessToken realm: nil signatureProvider:nil]; 
    if (method) { 
     [theRequest setHTTPMethod:method]; 
    } 
    [theRequest setHTTPShouldHandleCookies:NO]; 

    // Set headers for client information, for tracking purposes at Twitter. 
    [theRequest setValue:_clientName forHTTPHeaderField:@"X-Twitter-Client"]; 
    [theRequest setValue:_clientVersion forHTTPHeaderField:@"X-Twitter-Client-Version"]; 
    [theRequest setValue:_clientURL  forHTTPHeaderField:@"X-Twitter-Client-URL"]; 

    // Set the request body if this is a POST request. 
    BOOL isPOST = (method && [method isEqualToString:@"POST"]); 
    if (isPOST) { 
     // Set request body, if specified (hopefully so), with 'source' parameter if appropriate. 
     NSString *finalBody = @""; 
     if (body) { 
      finalBody = [finalBody stringByAppendingString:body]; 
     } 
     if (_clientSourceToken) { 
      finalBody = [finalBody stringByAppendingString:[NSString stringWithFormat:@"%@source=%@", (body) ? @"&" : @"?" , _clientSourceToken]]; 
     } 

     if (finalBody) { 
      [theRequest setHTTPBody:[finalBody dataUsingEncoding:NSUTF8StringEncoding]]; 
     } 
    } 
    [theRequest prepare]; 

    // Create a connection using this request, with the default timeout and caching policy, 
    // and appropriate Twitter request and response types for parsing and error reporting. 
    MGTwitterHTTPURLConnection *connection; 
    connection = [[MGTwitterHTTPURLConnection alloc] initWithRequest:theRequest delegate:self requestType:requestType responseType:responseType]; 

    if (!connection) { 
     return nil; 
    } else { 
     [_connections setObject:connection forKey:[connection identifier]]; 
    } 

    return [connection identifier]; 
} 

Báo cáo tai nạn là,

0 0x01f023ef in CFRelease() 
1 0x0008d04c in -[OAMutableURLRequest URLEncodedString:] (self=0x7bc673b0,  _cmd=0x9ee5f, string=0x0) at /Users/ben/Dropbox/Dev/External Projects/Twitter-OAuth-iPhone/OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAMutableURLRequest.m:287 
2 0x0008bbe3 in -[OAMutableURLRequest prepare] (self=0x7bc673b0, _cmd=0x978cc) at /Users/ben/Dropbox/Dev/External Projects/Twitter-OAuth-iPhone/OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAMutableURLRequest.m:131 
3 0x00088460 in -[SA_OAuthTwitterEngine _sendRequestWithMethod:path:queryParameters:body:requestType:responseType:] (_cmd=0x96833, method=0xc0250, body=0x7b971210, requestType=<value temporarily unavailable, due to optimizations>) at SA_OAuthTwitterEngine.m:315 

4 0x0007f673 in -[MGTwitterEngine sendUpdate:inReplyTo:] (self=<value temporarily unavailable, due to optimizations>, _cmd=0x96914, updateID=2073243024) at MGTwitterEngine.m:1019 

5 0x0007f496 in -[MGTwitterEngine sendUpdate:] (self=0x7b932d90, _cmd=0x95e02, status=0xc0510) at MGTwitterEngine.m:995 

6 0x0007bf3f in -[DMUAppDelegate OAuthTwitterController:authenticatedWithUsername:] (self=0x7b918a20, _cmd=0x96152) at DMUAppDelegate.m:572 

7 0x0008503b in -[SA_OAuthTwitterController gotPin:] (_cmd=0x975b4, pin=0x7ae573e0) at SA_OAuthTwitterController.m:125 

8 0x00086137 in -[SA_OAuthTwitterController webViewDidFinishLoad:] (self=0x7b944a00, _cmd=0xf070e2, webView=0x7ae46750) at SA_OAuthTwitterController.m:224 

9 0x00be036a in -[UIWebView webView:didFinishLoadForFrame:]() 

10 0x00be1956 in -[UIWebViewWebViewDelegate webView:didFinishLoadForFrame:]() 

11 0x01f5c51d in __invoking___() 

12 0x01f5c437 in -[NSInvocation invoke]() 

13 0x01f8749a in -[NSInvocation invokeWithTarget:]() 

14 0x03462aff in -[_WebSafeForwarder forwardInvocation:]() 
15 0x01f5d0c9 in ___forwarding___() 
16 0x01f5cce2 in __forwarding_prep_0___() 

17 0x01f5c51d in __invoking___() 
18 0x01f5c437 in -[NSInvocation invoke]() 

19 0x04005ae3 in SendMessage() 
20 0x04006115 in HandleDelegateSource() 

21 0x01fca97f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__() 
22 0x01f2db73 in __CFRunLoopDoSources0() 
23 0x01f2d454 in __CFRunLoopRun() 
24 0x01f2cdb4 in CFRunLoopRunSpecific() 
25 0x01f2cccb in CFRunLoopRunInMode() 
26 0x01e60879 in GSEventRunModal() 
27 0x01e6093e in GSEventRun() 

28 0x00a29a9b in UIApplicationMain() 
29 0x00040296 in main (argc=1, argv=0xc003c604) at /Users/dhirenshah/Desktop/Projects/Projects/DMU/DMU/main.m:16 
(gdb) 

Trả lời

3

Vâng, cuối cùng tôi giải quyết vấn đề của tôi. i Chỉ cần thay thế mã,

- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate 
    { 

    if (self = (id) [super initWithDelegate: delegate]) { 
     self.requestTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/request_token"]; 
     self.accessTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/access_token"]; 
     self.authorizeURL = [NSURL URLWithString: @"https://twitter.com/oauth/authorize"]; 
    } 
    return self; 
} 

Sửa đổi hàm SA_OAuthTwitterEngine.m. Tôi được trợ giúp từ số MGTwitterEngine crash in iOS5, liên kết này.

+0

không hoạt động đối với tôi. –

+0

lỗi nào bạn gặp phải? @ArnleeVizcayno – Tirth

+0

hiện tại, tôi đang sử dụng iOS 6.1.3 trên iPhone 4s. Nó không thực sự cho tôi một lỗi, nó chỉ sụp đổ và khi tôi theo dõi nó, nó trỏ đến phương pháp [theRequest preparation]. Tôi cũng đã theo dõi cố định từ liên kết bạn đã đưa vào. –

0

Tôi đã thực hiện thay đổi trong mã trên, vì api twitter đã được thay đổi nên mã cũ sẽ không hoạt động.

Và đối với bất kỳ người dùng mới nếu họ đang sử dụng các định dạng trên với MGTwitterEnginer, nó sẽ không làm việc, bạn sẽ cần phải thay thế

self.requestTokenURL = [NSURL URLWithString: @ "https: //api.twitter .com/oauth/request_token "]; self.accessTokenURL = [URL NSNVới chuỗi: @ "https://api.twitter.com/oauth/access_token"]; self.authorizeURL = [URL của NSURLVới chuỗi: @ "https://api.twitter.com/oauth/authorize"];

1

Tôi đang chạy iOS 6.1.3 và thiết bị của tôi để thử nghiệm là iPhone 4s. Tôi đã nhận được lỗi/sự cố tương tự mà xcode đã chỉ ra sự cố đến phương thức [theRequest prepare];.

My cố định là:

 OAMutableURLRequest *theRequest = [[[OAMutableURLRequest alloc]   
       initWithURL:finalURL 
       consumer:self.consumer 
       token:_accessToken 
       realm: nil 
       signatureProvider:nil] autorelease]; 

đặt autorelease trên dòng này và kiểm tra một lần nữa [_engine isAuthorized] trước khi gửi bài tweet:

 if ([_engine isAuthorized]) 
     { 
      NSLog(@"post Tweet"); 
      . . . . . . 
     } else { 
      NSLog(@"cant post Tweet"); 
      . . . . . . 
     } 

Tôi không thể expalin thêm hơn, vì tôi chưa quen thuộc với điều này nhưng điều này làm việc cho tôi.

+0

cool.Thanks để chia sẻ giải pháp của bạn cùng với câu hỏi này. – Tirth

Các vấn đề liên quan