在 Xcode 8/iOS 10 之前,我能够从静态库的单元测试中访问钥匙串。升级后,出现错误,请参阅堆栈跟踪:
failed: caught "NSInternalInconsistencyException", "Couldn't add the Keychain Item."
(
0 CoreFoundation 0x000000010b2a734b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ad0821e objc_exception_throw + 48
2 CoreFoundation 0x000000010b2ab442 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010a89eedd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 MyLibTests 0x0000000117366dea -[KeychainItemWrapper writeToKeychain] + 970
5 MyLibTests 0x000000011736614a -[KeychainItemWrapper setObject:forKey:] + 218
6 MyLibTests 0x000000011736a794 -[MyUserManager(Credentials) save] + 196
7 PawPointsLibTests 0x0000000116ef5490 -[MyLibTest tearDown] + 256
8 XCTest 0x000000010a6e0547 __24-[XCTestCase invokeTest]_block_invoke_2 + 1304
9 XCTest 0x000000010a7189d4 -[XCTestContext performInScope:] …Run Code Online (Sandbox Code Playgroud)