1

昨晚我写了一个函数来调用一些云代码,它工作正常。

现在,当我运行相同的代码时,我会崩溃......

#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}";
}

我仍然遇到同样的崩溃。

4

1 回答 1

3

我认为您目前不能将 PFObjects 作为参数传递给云函数。NoObjectEncodingStrategy(您在调用堆栈中看到的内部实现细节)明确禁止这样做。异常应该有一个错误信息。

相反,您应该在云函数中传递您想要的任何对象的对象 ID,并在必要时在服务器端查找它们。

这里的原因是对于具有未决更改或未保存对象的对象没有标准格式(例如,如果您查看用于 Parse 的 REST API),因此在许多情况下传递 PFObject 会产生未定义或至少是意外行为。这可能有一天会改变,但这是一种旨在避免混淆的限制。

于 2014-11-22T07:43:15.703 回答