0

Having a bit of an issue with using keychain to store login information to my app. It works perfectly fine and will display the information when I go in and out of other apps but once I fully close down the app and try to reopen it and click to bring back up the login information the app crashes. I will attach the code and also the error log. I do understand that using this version of keychain isn't done by most people from my reading online people seem to use alternative keychain scripts but hopefully someone has run into this problem. I have 3 buttons and 2 text fields to test it. One text field for username, one for password then I have a button to sign in which saves the information, a button to view the information then a logout button.

Thanks.

Dec 31 01:58:13 Curtis-iPhone uDropOff 3[18034] : -[__NSCFData rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x147ed0338 Dec 31 01:58:13 Curtis-iPhone uDropOff 3[18034] : * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x147ed0338' * First throw call stack: (0x180eed900 0x18055bf80 0x180ef461c 0x180ef15b8 0x180df568c 0x186529988 0x185c206f4 0x1000c0194 0x185c17e50 0x185c17dcc 0x185bffa88 0x185c176e4 0x185c17314 0x185c0fe30 0x185be04cc 0x185bde794 0x180ea4efc 0x180ea4990 0x180ea2690 0x180dd1680 0x1822e0088 0x185c48d90 0x1000c4980 0x1809728b8) Dec 31 01:58:13 Curtis-iPhone SpringBoard[15499] : HW kbd: Failed to set (null) as keyboard focus Dec 31 01:58:13 Curtis-iPhone com.apple.xpc.launchd[1] (UIKitApplication:uDropOff.uDropOff-3[0x44ca][18034]) : Service exited due to signal: Abort trap: 6 Dec 31 01:58:13 Curtis-iPhone diagnosticd[15528] : unable to find offset 0x809679a4 in shared cache for arch 'arm64' Dec 31 01:58:13 Curtis-iPhone ReportCrash[18035] : platform_thread_get_unique_id matched 6392471 Dec 31 01:58:13 Curtis-iPhone ReportCrash[18035] : Formulating report for corpse[18034] uDropOff 3 Dec 31 01:58:13 Curtis-iPhone ReportCrash[18035] : saved type '109_uDropOff 3' report (5 of max 25) as /var/mobile/Library/Logs/CrashReporter/uDropOff 3_2015-12-31-015813_Curtis-iPhone.ips Dec 31 01:58:13 Curtis-iPhone SpringBoard[15499] : Application 'UIKitApplication:uDropOff.uDropOff-3[0x44ca]' crashed. Dec 31 01:58:13 Curtis-iPhone UserEventAgent[15467] : 20372720635010: id=uDropOff.uDropOff-3 pid=18034, state=0 Dec 31 01:58:23 Curtis-iPhone locationd[15505] : Location icon should now be in state 'Inactive'

- (void)viewDidLoad
{

    [super viewDidLoad];

    keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"uDropOffLoginData" accessGroup:nil];

}
- (IBAction)viewkeychain {
    if ([[keychain objectForKey:(id)kSecAttrAccount]  isEqual: @""])
    {
        self.username.text = @"nousername";
        self.password.text = @"nopassword";

    }
    else
    {
    self.username.text = [keychain objectForKey:(id)kSecAttrAccount];
    self.password.text = [keychain objectForKey:(id)kSecValueData];
    }


}
- (IBAction)logout {
    [keychain resetKeychainItem];

}
    - (IBAction)signin {
    [keychain setObject:[_username text] forKey:(id)kSecAttrAccount];
    [keychain setObject:[_password text] forKey:(id)kSecValueData];


}
Curtis Boylan
  • 827
  • 1
  • 7
  • 23
  • Check the call stack in Xcode when the crash happens, and tell us where in your code the crash happens. – jcaron Dec 31 '15 at 02:20
  • Would you be able to tell me how to do that? I didn't know there was a way to keep that running after I have closed the app in the app switcher it disconnects from Xcode. – Curtis Boylan Dec 31 '15 at 02:24
  • can you reproduce it? if can, you can try to log out what is the value of [_username text] and [_password text], it looks to me that these two is not valid – Surely Dec 31 '15 at 04:49
  • @CurtisBoylan you should get the same behaviour when you relaunch the app from SpringBoard and when you relaunch it from Xcode, don't you? Otherwise you should have a crash log which can be used for the same purpose. – jcaron Dec 31 '15 at 09:24
  • Everything works fine the saving seems to work okay until I close the app then reopen and try view the saved data. I can go to another app and leave that app open in the background then go back to it and it's still saved but if I close it using the app switcher it crashes when I reopen it and click to get the saved info. – Curtis Boylan Dec 31 '15 at 09:34
  • Here is what the Xcode debug seems to give. 2015-12-31 10:26:54.899 uDropOff 3[2571:41130] -[__NSCFData rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7f94f2d65ac8 2015-12-31 10:26:54.937 uDropOff 3[2571:41130] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7f94f2d65ac8' – Curtis Boylan Dec 31 '15 at 10:28

1 Answers1

0

I have fixed this code myself, by changing kSecValueData to kSecAttrService everything works fine and the crash no longer happens.

Curtis Boylan
  • 827
  • 1
  • 7
  • 23