昨晚我编写了一个函数来调用一些云代码,并且运行良好。
现在,当我运行相同的代码时,我崩溃了……
#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}";
}
而且我仍然遇到同样的崩溃。
最佳答案
我认为您目前无法将PFObjects作为参数传递给云函数。 NoObjectEncodingStrategy(您在调用堆栈中看到的内部实现详细信息)明确禁止这样做。异常应该具有一条错误消息,以达到这种效果。
相反,您应该在云函数中传递任何想要的对象的对象ID,并在必要时在服务器端查找它们。
这里的理由是,对于具有待定更改或未保存对象的对象,没有标准格式(例如,如果您查看用于解析的REST API),因此在许多情况下,传递PFObject会具有未定义或至少是意外行为。可能有一天会改变,但这是为了避免混乱的限制。
关于ios - 解析云代码调用中突然崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27036124/