8

From AppDelegate i call this:

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

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

And then i get this error when calling the reply:

*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'This decoder will only decode classes that adopt NSSecureCoding. Class 'Test.MatchCollection' does not adopt it.'

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

As long as i return simply objects like "test" instead of a MatchCollection i get no error.

Godfather
  • 4,040
  • 6
  • 43
  • 70
  • Possible duplicate of [Parse and watchkit extension](http://stackoverflow.com/questions/30366934/parse-and-watchkit-extension) – Larme Jul 26 '16 at 12:05
  • Do you ever read and try [Parse and watch kit extension](http://stackoverflow.com/questions/30366934/parse-and-watchkit-extension) and [When to use NSSecureCoding](http://stackoverflow.com/questions/17301769/when-to-use-nssecurecoding) – Pierre Charpentier Aug 01 '16 at 10:16
  • Generally, you can decode objects that only adhere to `NSCoding` but not `NSSecureCoding` using the technique from this answer: https://stackoverflow.com/a/68522427/10601702. (Doesn't work for this question though, because they don't seem to control **how** their data is decoded) – Noah Nuebling Jul 25 '21 at 21:19

2 Answers2

12

add in .h file

 // just the protocol

@interface PacketH: NSObject<NSSecureCoding>

add in .m file

+ (BOOL)supportsSecureCoding {
   return YES;
}
dengApro
  • 3,848
  • 2
  • 27
  • 41
1

If you are using Swift, you need to implement NSSecureCoding protocol to your class:

class Foo: NSObject, NSSecureCoding {
    static var supportsSecureCoding: Bool {
       return true
    }
}
pableiros
  • 14,932
  • 12
  • 99
  • 105