Start a new topic
Answered

KinveyException, Could not write token to keychain. Err 34018

I am migrating my backend service from parse to kinvey but get slammed with the above error message and termination of my app. 

Happens with the emulator but also when running on real phone device. 


I have not included any big chunks of kinvey related code yet. Basically just the code below:


In AppDelegate.m:

//kinvey

NSString *APP_KEY = @"abc_....";

NSString *APP_SECRET = @"...333";

 


..



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

 

  ...

 

    //Kinvey use code: You'll need to create an app on the backend and initialize it here:

    //http://docs.kinvey.com/ios-developers-guide.html#Initializing_Programmatically

    KCSClientConfiguration* config = [KCSClientConfiguration configurationWithAppKey:APP_KEY secret:APP_SECRET];

    [[KCSClient sharedClient] initializeWithConfiguration:config];

 

}



---------


And in the LoginScreen.m:


...

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

 

    [self createNewAccount];

}

...


- (void)createNewAccount{


    if ([KCSUser activeUser] == nil) {

        [KCSUser createAutogeneratedUser:@{KCSUserAttributeEmail : @"kinvey@kinvey.com", KCSUserAttributeGivenname : @"ArnoldWolfgang", KCSUserAttributeSurname : @"Kinvey"} completion:^(KCSUser *user, NSError *errorOrNil, KCSUserActionResult result) {

            //do something

        }];

    } else {

        //otherwise user is set and do something

    }


}

-----


I just wanted to include an auto created user for quick test of the system. Actually my app will not ask for registration, if users don't want to register. So, a working auto created user would be fine for the final version as well. 


Running it, the user actually is created in the kinvey backend every time it runs; however terminates and provides the following error message:


2016-10-01 16:23:15.009 AppName[91983:1756853] *** Terminating app due to uncaught exception 'KinveyException', reason: 'Could not write token to keychain. Err (null) (-34018)'

 2   AppName                0x000000010c1afd83 +[KCSKeychain2 setKinveyToken:user:] + 1411

 3   AppName                0x000000010c1f8b82 +[KCSUser2(KinveyUserService) setupActiveUser:completion:checkAuth:] + 882

 4   AppName                0x000000010c1f2d92 __90+[KCSUser2(KinveyUserService) createUserWithUsername:password:fieldsAndValues:completion:]_block_invoke.45 + 530


Anybody experienced the same or has an idea how to solve?


Best Answer
Martin,

For error "'KinveyException', reason: 'Could not write token to keychain. Err (null) (-34018)'", this seems to be an issue with iOS simulator. Please take a look at following links:

https://forums.developer.apple.com/thread/51071
https://openradar.appspot.com/27844971



 Workaround for this is sharing the Keychain (which can also allows your keychain between your apps). Take a look at this link http://evgenii.com/blog/sharing-keychain-in-ios/.


Thanks,

Pranav

Kinvey Support


Arnold,

Glad that your issue has been resolved! Let me know if you have more questions.

Thanks,
Pranav
Kinvey Support

 

thx Pranav, sharing the keychain also worked for me. 

Also, using the device and not the simulator was also a useful hint.

Awesome.. Turning on the "Keychain Sharing" capability solved my problem 

Answer
Martin,

For error "'KinveyException', reason: 'Could not write token to keychain. Err (null) (-34018)'", this seems to be an issue with iOS simulator. Please take a look at following links:

https://forums.developer.apple.com/thread/51071
https://openradar.appspot.com/27844971



 Workaround for this is sharing the Keychain (which can also allows your keychain between your apps). Take a look at this link http://evgenii.com/blog/sharing-keychain-in-ios/.


Thanks,

Pranav

Kinvey Support

I'm also getting: 

'KinveyException', reason: 'Could not write token to keychain. Err (null) (-34018)'


I'm using iOS 10, Xcode 8 and SDK version 1.41.1.


The problem only occurs when I'm running on the simulator. When I run an iPhone (6) I have no problem. I have had this problem with the simulator for a while. See this thread: https://support.kinvey.com/support/discussions/topics/12000005303

 

Hello Pranav,

thanks for getting back to me. 

1. I use version 1.41.0 of the iOS SDK

2. 

 Version: 8.0 (8A218a)

  Location: /Applications/Xcode.app

  Applications:

  Xcode: 8.0 (11246)

  Instruments: 8.0 (61187)

  SDKs:

  iOS:

  10.0: (14A345)

  iOS Simulator:

  10.0: (14A345)

  macOS:

  10.12: (16A300)

  tvOS:

  10.0: (14T328)

  tvOS Simulator:

  10.0: (14T328)

  watchOS:

  3.0: (14S326)

  watchOS Simulator:

  3.0: (14S326)

3. many of them fail but to a number of causes

for instance the test drive sample

Terminating app due to uncaught exception 'KinveyInitializationError', reason: '`nil` or invalid appKey, cannot use Kinvey Service, no recovery available'


Does it help?

I am having the exact same issue but with the iOS v3 SDK.  I am using Xcode 8.0


*** Terminating app due to uncaught exception 'KinveyException', reason: 'Could not write token to keychain. Err (null) (-34018)'


 I think there is an issue with the KeychainAccess dependency when updating to Swift 3.  There were some errors with it that I fixed last pm to even get it to compile (ambiguity with parameter and method names) so my suspicion lies here.  


Thanks,


Mark

Arnold,

  1. What version of Kinvey SDK are you using?
  2. What is the Xcode version and what is the iOS SDK version where you see in the issue?
  3. Also just in case you have tried - wanted to check if you were able to execute any of the Kinvey sample apps earlier?

 


Thanks,

Pranav

Kinvey Support

Login or Signup to post a comment