0

My app doesn't crash when I run it from XCode, but I created an IPA to use with TestFlight, and it crashes after the user attempts to log into the app. I believe it's due to using the keychainItemWrapper library defined here: https://gist.github.com/dhoerl/1170641

This is what my crash report looks like:

Incident Identifier: 906A698B-555F-4922-8596-27FE481E9522
CrashReporter Key:   8722e51d4300c003d1ac939808b1a9c67f112194
Hardware Model:      iPhone6,1
Process:             -
Path:                /var/mobile/Applications/B2EFB5F3-86C0-4E87-850D-27F771A1FA41/App.app/App
Identifier:          -
Version:             1.0 (1.0)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2014-09-08 21:10:03.911 -0400
OS Version:          iOS 7.1.2 (11D257)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000008945bec8
Triggered by Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                 0x00000001991ac0b8 objc_retain + 24
1   App                             0x000000010008118c -[LoginViewController loginClick:] (LoginViewController.m:246)
...

At line 246 of the LoginViewController, I run the following method:

        [self authenticateUser];

Which is defined below:

-(IBAction)authenticateUser {
    [keychainItem resetKeychainItem]; // remove any existing auth_token

   [keychainItem setObject:[_txtUsername text] forKey:(__bridge id)(kSecAttrAccount)];

    NSURL *url=[NSURL URLWithString:sessionsBaseURL];
    NSError *error = [[NSError alloc] init];
    NSDictionary * userDict = [[NSDictionary alloc] initWithObjectsAndKeys: [_txtUsername text], @"username", [_txtPassword text], @"password", nil];
    NSDictionary * holderDict = [[NSDictionary alloc] initWithObjectsAndKeys: userDict, @"user", nil];
    NSLog(@"user holderDict: %@", holderDict);
    NSData * holder = [NSJSONSerialization dataWithJSONObject:holderDict options:0 error:&error];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:holder];

    NSURLResponse * response = nil;
    NSData * receivedData = nil;

    receivedData = [NSMutableData data];
    receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    // get dictionary from json data
    NSDictionary * jsonResponse = [NSJSONSerialization
                                   JSONObjectWithData: receivedData
                                   options:kNilOptions
                                   error:&error];

    NSLog(@"jsonResponse: %@", jsonResponse);
    NSDictionary * dataResponse = [jsonResponse objectForKey:@"data"];
    auth_token = [dataResponse objectForKey:@"auth_token"];

    // save user authentication token in NSUserDefaults
    NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults];    
    [keychainItem setObject:[dataResponse objectForKey:@"auth_token"] forKey:(__bridge id)(kSecValueData)];

    [self checkLoginApproved];
}

I would really appreciate any help on this as it's preventing me from releasing my app!

scientiffic
  • 9,045
  • 18
  • 76
  • 149

1 Answers1

2

Do you create your KeychainItemWrapper with accessGroup:nil? Try using a string - it helped for me

[[KeychainItemWrapper alloc] initWithIdentifier:@"userCredentials" accessGroup:@"reverse.tld.example"];
Adriano
  • 482
  • 5
  • 18