Loading ...

SecItemAdd returns error -34018 in xcode 8 in iOS 10 simulator and works in physical device | CodeAsp.Net

SecItemAdd returns error -34018 in xcode 8 in iOS 10 simulator and works in physical device

 /5
0 (0votes)

Problem:

I was having trouble saving sensitive data in KeyChain while running in Xcode 8 in iOS 10 simulator. The following code returns NO if I run in Simulator and the same code returns YES when running in physical device / iPhone

+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error {
	SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
	query.service = serviceName;
	query.account = account;
	query.password = password;
        return [query save:error];
}

Above code is copied from SSKeyChain.m file

I got the error code -34018 (errSecMissingEntitlement) when started debugging further.

The solution:

Solution is easy and simple: Enable KeyChain Sharing under Capabilities pane in the project editor for your target.

Comments (no comments yet)

Top Posts