昨晚我编写了一个函数来调用一些云代码并且工作正常。
现在,当我运行相同的代码时,我得到了崩溃...
#2 0x000000010e3e28f4 in -[PFNoObjectEncodingStrategy encodeRelatedObject:] at /Users/nlutsenko/src/parse/ios-client/Parse/Internal/PFObjectEncodingStrategy.m:17
我以前从未见过这次崩溃。
我的云代码调用是......
- (void)getFollowStats
{
[PFCloud callFunctionInBackground:@"followStats" withParameters:@{@"user": self.user} block:^(NSDictionary *result, NSError *error) {
if (error) {
NSLog(@"Error! %@ : %@", error, error.userInfo);
} else {
}
}];
}
由于@{@"user": self.user}
参数,崩溃正在发生。如果我删除用户对象,它不会崩溃。但昨晚工作正常。
整个调用堆栈
#0 0x00000001119a3b8a in objc_exception_throw ()
#1 0x0000000111d0ae6d in +[NSException raise:format:] ()
#2 0x000000010e3e28f4 in -[PFNoObjectEncodingStrategy encodeRelatedObject:] at /Users/nlutsenko/src/parse/ios-client/Parse/Internal/PFObjectEncodingStrategy.m:17
#3 0x000000010e428520 in +[PFInternalUtils encodeObject:withObjectEncoder:] at /Users/nlutsenko/src/parse/ios-client/Parse/Internal/PFInternalUtils.m:456
#4 0x000000010e428b63 in +[PFInternalUtils encodeObject:withObjectEncoder:] at /Users/nlutsenko/src/parse/ios-client/Parse/Internal/PFInternalUtils.m:513
#5 0x000000010e42c675 in +[PFCloud callFunctionInBackground:withParameters:] at /Users/nlutsenko/src/parse/ios-client/Parse/PFCloud.m:29
#6 0x000000010e42c9c2 in +[PFCloud callFunctionInBackground:withParameters:block:] at /Users/nlutsenko/src/parse/ios-client/Parse/PFCloud.m:56
#7 0x000000010e392712 in -[CCAccountDataSource getFollowStats] at /Users/oliverfoggin/Documents/emojicate/Emojicate/Account View/Account Data Source/CCAccountDataSource.m:48
#8 0x000000010e3922cc in -[CCAccountDataSource fetchUserDetails] at /Users/oliverfoggin/Documents/emojicate/Emojicate/Account View/Account Data Source/CCAccountDataSource.m:27
#9 0x000000010e36bb9f in -[CCAccountViewController viewDidLoad] at /Users/oliverfoggin/Documents/emojicate/Emojicate/Account View/CCAccountViewController.m:86
#10 0x0000000110353a90 in -[UIViewController loadViewIfRequired] ()
#11 0x0000000110353c8e in -[UIViewController view] ()
#12 0x0000000110377507 in -[UINavigationController _startCustomTransition:] ()
#13 0x00000001103833fe in -[UINavigationController _startDeferredTransitionIfNeeded:] ()
#14 0x0000000110383f47 in -[UINavigationController __viewWillLayoutSubviews] ()
#15 0x00000001104c9509 in -[UILayoutContainerView layoutSubviews] ()
#16 0x0000000121ef6a5e in -[UILayoutContainerViewAccessibility layoutSubviews] ()
#17 0x00000001102a7973 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#18 0x000000010ff3bde8 in -[CALayer layoutSublayers] ()
#19 0x000000010ff30a0e in CA::Layer::layout_if_needed(CA::Transaction*) ()
#20 0x000000010ff3087e in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()
#21 0x000000010fe9e63e in CA::Context::commit_transaction(CA::Transaction*) ()
#22 0x000000010fe9f74a in CA::Transaction::commit() ()
#23 0x000000010fe9fdb5 in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) ()
#24 0x0000000111c3fdc7 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#25 0x0000000111c3fd20 in __CFRunLoopDoObservers ()
#26 0x0000000111c35b53 in __CFRunLoopRun ()
#27 0x0000000111c35486 in CFRunLoopRunSpecific ()
#28 0x0000000112e9d9f0 in GSEventRunModal ()
#29 0x000000011022e420 in UIApplicationMain ()
#30 0x000000010e3970c3 in main at /Users/oliverfoggin/Documents/appName/appName/main.m:16
#31 0x0000000112237145 in start ()
参数字典
我将参数字典拆分成var并记录下来,这就是我得到的......
{
user = "
<PFUser: 0x7blahblha0, objectId: blahblah, localId: (null)>
{
authData = {
facebook = {
"access_token" = blahblahblahblah;
"expiration_date" = "2016-11-19T09:32:19.434Z";
id = 1234567;
};
};
avatar = "<PFFile: 0x7fc1b1c3ffb0>";
canonicalName = "oliver foggin";
emoji = "<PFFile: 0x7fc1b1c41170>";
fbId = 723405322;
friendIds = (
8765586,
23452345,
2345123
);
fullName = "Oliver Foggin";
onboardComplete = 1;
username = blahblahblahblah;
}";
}
我已从此删除所有安全信息并更改了ID号。
我昨天添加的是friendIds
数组。但是昨天早上又添加了这个代码,这段代码工作时间是昨晚18:10。
好的,WTF?这很奇怪
我用这个代替了参数代码......
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
if (self.user) {
parameters[@"user"] = [PFObject objectWithoutDataWithClassName:@"_User" objectId:self.user.objectId];
}
所以现在它甚至没有使用用户对象,它正在创建一个带有对象ID的虚假“用户”对象。
参数字典看起来像这样......
{
user = "<PFUser: 0x7fd770cc1020, objectId: ez0KCzD6Th, localId: (null)> {\n}";
}
我仍然遇到同样的崩溃。
答案 0 :(得分:3)
我认为您目前无法将PFObjects作为参数传递给云端功能。 NoObjectEncodingStrategy(您在调用堆栈中看到的内部实现细节)明确禁止此操作。该异常应该有一个错误消息。
相反,您应该在云功能中传递您想要的任何对象的对象ID,并在必要时在服务器端查找它们。
这里的推理是没有标准格式(例如,如果你看待用于Parse的REST API)对于具有挂起更改或未保存对象的对象,所以在很多情况下传递PFObject会有未定义或至少是意外的行为。这可能有一天会改变,但这是一种旨在避免混淆的限制。