简体   繁体   中英

App crashes when tries to connect twitter in ios

In my iPhone app i am implementing the twitter share feature using ShareKit. When I tried to share via twitter in device, the app is crashing at

- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection

And I got the error message;

NSInvalidArgumentException, [NSCFType tokenRequestTicket:didFinishWithData]:

But it is running fine on simulator. And I used the same code without any change in another application before, and it is still running fine. The issue is only in newly created app.

Please help, and if somebody need more details please let me know.

Update These are methods called

 - (void)tokenRequest
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ShareStarted" object:nil];
    [[SHKActivityIndicator currentIndicator] displayActivity:SHKLocalizedString(@"Connecting...")];
    NSLog(@"Url: %@\n Token: %@ \n Consumer: %@\n Key: %@",requestURL, requestToken, consumer, consumerKey);
    OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:requestURL
                                                                   consumer:consumer
                                                                      token:nil   // we don't have a Token yet
                                                                      realm:nil   // our service provider doesn't specify a realm
                                                           signatureProvider:signatureProvider];


    [oRequest setHTTPMethod:@"POST"];

    [self tokenRequestModifyRequest:oRequest];

    OAAsynchronousDataFetcher *fetcher = [OAAsynchronousDataFetcher asynchronousFetcherWithRequest:oRequest
                         delegate:self
                didFinishSelector:@selector(tokenRequestTicket:didFinishWithData:)
                  didFailSelector:@selector(tokenRequestTicket:didFailWithError:)];
    [fetcher start];    
    [oRequest release];
}

- (void)tokenRequestTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data 
{
    if (SHKDebugShowLogs) // check so we don't have to alloc the string with the data if we aren't logging
        SHKLog(@"tokenRequestTicket Response Body: %@", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);

    [[SHKActivityIndicator currentIndicator] hide];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"SharingCancel" object:nil];
    if (ticket.didSucceed) 
    {
        NSString *responseBody = [[NSString alloc] initWithData:data
                                                       encoding:NSUTF8StringEncoding];
        OAToken *aToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
        [responseBody release];
        self.requestToken =  aToken;
        [aToken release];       

        [self tokenAuthorize];
    }

    else
        // TODO - better error handling here
        [self tokenRequestTicket:ticket didFailWithError:[SHK error:SHKLocalizedString(@"There was a problem requesting authorization from %@", [self sharerTitle])]];
}

Update Error point

libobjc.A.dylib`objc_msgSend:
0x360a25a0:  teq.w  r0, #0
0x360a25a4:  beq    0x360a25e6                ; objc_msgSend + 70
0x360a25a6:  push.w {r3, r4}
0x360a25aa:  ldr    r4, [r0]
0x360a25ac:  lsr.w  r9, r1, #2
0x360a25b0:  ldr    r3, [r4, #8]
0x360a25b2:  add.w  r3, r3, #8
0x360a25b6:  ldr    r12, [r3, #-8]
0x360a25ba:  and.w  r9, r9, r12
0x360a25be:  ldr.w  r4, [r3, r9, lsl #2]   //here EXC_BAD_ACCESS happened
0x360a25c2:  teq.w  r4, #0
0x360a25c6:  add.w  r9, r9, #1
0x360a25ca:  beq    0x360a25e0                ; objc_msgSend + 64
0x360a25cc:  ldr.w  r12, [r4]
0x360a25d0:  teq.w  r1, r12
0x360a25d4:  bne    0x360a25b6                ; objc_msgSend + 22
0x360a25d6:  ldr.w  r12, [r4, #8]
0x360a25da:  pop.w  {r3, r4}
0x360a25de:  bx     r12
0x360a25e0:  pop.w  {r3, r4}
0x360a25e4:  b      0x360a2600                ; objc_msgSend_uncached
0x360a25e6:  mov.w  r1, #0
0x360a25ea:  bx     lr
0x360a25ec:  nop    
0x360a25ee:  nop    
0x360a25f0:  nop    
0x360a25f2:  nop    
0x360a25f4:  nop    
0x360a25f6:  nop    
0x360a25f8:  nop    
0x360a25fa:  nop    
0x360a25fc:  nop    
0x360a25fe:  nop    

ShareKit will try to use the navigation controller stack to find your root view controller , then pop a modal view controller from there. It throws this error when it can't find one.

You can correct it by manually setting the root view controller by using the following call:

[SHK setRootViewController:myViewController];

Check answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM