我一整天都在试图弄清楚我做错了什么,但我完全不知道为什么应用程序总是崩溃。
情况如下:
我已经建立了一个简单的项目,实现了所有必需的库和框架。我使用以下实例方法创建了几个 Parse 用户:
[self signUpUserWithName:@"nico" withPassword:@"123"];
[self signUpUserWithName:@"gabriel" withPassword:@"123"];
[self signUpUserWithName:@"bruno" withPassword:@"123"];
在这里可以看到方法实现:
-(void)signUpUserWithName:(NSString *)username withPassword:(NSString *)password{
PFUser* user = [PFUser user];
user.password = password;
user.username = username;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(!error){
NSLog(@"User created.");
}
else{
NSLog(@"User couldn't be created.");
}
}];
}
这按预期工作,创建了用户并且一切都很好。现在我正在登录一个用户并使用以下代码为当前用户创建一个 PFUser 对象:
[PFUser logInWithUsername:@"user1" password:@"123"];
//Fetching Current User
PFUser* currentUser = [PFUser currentUser];
if ([currentUser isAuthenticated]){
NSLog(@"Authenticated");
}
else{
NSLog(@"Not Authenticated");
}
这也按预期工作。用户已登录,我收到一个经过身份验证的 currentUser 对象。现在我正在尝试通过查询获取用户的对象,如果成功,将生成的对象分配给我 currentUser 的键“myfriends”(创建一对一关系)。
PFQuery* friendQuery = [PFUser query];
[friendQuery whereKey:@"username" equalTo:@"user2"];
[friendQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if(!error){
NSLog(@"%@",object);
currentUser[@"myfriends"] = object;
[currentUser save];
}
else{
NSLog(@"Failed getting User Object.");
}
}];
这也按预期工作。如果我现在在 Parse 中打开我的数据浏览器,我可以看到指向 user2 对象的指针已分配给“myfriends”。
但是如果我重新启动应用程序,就会发生崩溃。如果我为另一个 PFUser 的“myfriends”键分配了除 PFUser 之外的其他东西,例如带有一些数据的 PFObject,那么一切正常。没有崩溃,完美。但是如果我试图分配一个 PFUser,它会崩溃并显示以下消息:
2015-01-19 13:44:09.135 localizr[2320:281655] -[__NSCFBoolean _loadSensitiveUserDataFromKeychainItemWithName:]: unrecognized selector sent to instance 0x19967eb60
2015-01-19 13:44:09.136 localizr[2320:281655] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean _loadSensitiveUserDataFromKeychainItemWithName:]: unrecognized selector sent to instance 0x19967eb60'
*** First throw call stack:
(0x188301e48 0x1989fc0e4 0x188308f14 0x188305cc4 0x18820ac1c 0x1000758a4 0x10006f97c 0x10007f25c 0x10007ecbc 0x10007ead4 0x10000d1f8 0x18cb223d0 0x18cd39230 0x18cd3b9b0 0x18cd3a048 0x190565640 0x1882ba124 0x1882b922c 0x1882b742c 0x1881e51f4 0x18cb1b78c 0x18cb16784 0x10000d4c4 0x19906aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我究竟做错了什么?谢谢你的帮助。
最好的祝愿尼科
编辑:这是您要求的堆栈跟踪:
* thread #1: tid = 0xca4e, 0x0000000196d93270 libsystem_kernel.dylib`__pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0000000196d93270 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x0000000196e31228 libsystem_pthread.dylib`pthread_kill + 112
frame #2: 0x0000000196d0ab18 libsystem_c.dylib`abort + 112
frame #3: 0x0000000195df1418 libc++abi.dylib`abort_message + 116
frame #4: 0x0000000195e10b8c libc++abi.dylib`default_terminate_handler() + 304
frame #5: 0x000000019660c3c0 libobjc.A.dylib`_objc_terminate() + 128
frame #6: 0x0000000195e0dbb4 libc++abi.dylib`std::__terminate(void (*)()) + 16
frame #7: 0x0000000195e0d73c libc++abi.dylib`__cxa_rethrow + 144
frame #8: 0x000000019660c294 libobjc.A.dylib`objc_exception_rethrow + 44
frame #9: 0x0000000185df52a4 CoreFoundation`CFRunLoopRunSpecific + 572
frame #10: 0x000000018a72b78c UIKit`-[UIApplication _run] + 552
frame #11: 0x000000018a726784 UIKit`UIApplicationMain + 1488
* frame #12: 0x00000001001015d4 localizr`main(argc=1, argv=0x000000016fd03a68) + 116 at main.m:14
frame #13: 0x0000000196c7aa08 libdyld.dylib`start + 4