此解码器仅解码采用NSSecureCoding

时间:2016-07-26 11:50:32

标签: ios objective-c watchkit apple-watch watch-os

从AppDelegate我称之为:

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

    [SavedSearchesHack getAllMatches:^(MatchCollection * _Nonnull matchCollection) {
        reply(@{@"response" : matchCollection});
    }];
}

然后在调用回复时出现此错误:

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

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

只要我返回像“test”这样的对象而不是MatchCollection,我就不会收到任何错误。

1 个答案:

答案 0 :(得分:2)

添加.h文件

 // just the protocol

@interface PacketH: NSObject<NSSecureCoding>

添加.m文件

+ (BOOL)supportsSecureCoding {
   return YES;
}