此解码器只会解码采用 NSSecureCoding 的类

God*_*her 4 objective-c ios apple-watch watchkit watchos

从 AppDelegate 我称之为:

-(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{

    [SavedSearchesHack getAllMatches:^(MatchCollection * _Nonnull matchCollection) {
        reply(@{@"response" : matchCollection});
    }];
}
Run Code Online (Sandbox Code Playgroud)

然后我在调用回复时收到此错误:

*** 由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“此解码器将仅解码采用 NSSecureCoding 的类。'Test.MatchCollection' 类不采用它。

    public class func openParentApplication(userInfo: [NSObject : AnyObject], 
    reply: (([NSObject : AnyObject], NSError?) -> Void)?) -> Bool
Run Code Online (Sandbox Code Playgroud)

只要我简单地返回像“test”这样的对象而不是 MatchCollection,我就不会出错。

den*_*pro 6

添加到.h文件中

 // just the protocol

@interface PacketH: NSObject<NSSecureCoding>
Run Code Online (Sandbox Code Playgroud)

添加到.m文件中

+ (BOOL)supportsSecureCoding {
   return YES;
}
Run Code Online (Sandbox Code Playgroud)