2

Once a WKInterfaceController's didAppear function is fired, I send an empty NSData to WCSession's default session with the sendMessageData callback function:

// WKInterfaceController

NSData *emptyData = [[NSData alloc] init];
[[WCSession defaultSession] sendMessageData:emptyData replyHandler:^(NSData *replyMessageData) {
    NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:replyMessageData];
} errorHandler:^(NSError *error) {
    NSLog(@"WATCH: Error from replyData %@", error);
}];

The emptyData NSData object is sent because sendMessageData: is a non-null argument. I only use it to be able to fire WCSession's Delegate method, didReceiveMessageData on the iOS app. Then the replyHandler in that very function sends the appropriate data back to the replyHandler to the WKInterfaceController.

// UITableViewController

- (void)session:(WCSession *)session didReceiveMessageData:(NSData *)messageData replyHandler:(void (^)(NSData * _Nonnull))replyHandler
{
    [self loadData:nil onSuccess:^(NSArray *tips) {
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:tips];
        replyHandler(data);
    }];
}

The problem I'm having is that I get a crash on the following line in the WKInterfaceController

NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:replyMessageData];

Here's the error I get:

* Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Tip) for key (NS.objects); the class may be defined in source code or a library that is not linked'

What I've found so far:

Sorry for the long post but I've tried everything to find a solution to this problem, without success. Hope this helps more people that are having issues with WatchConnectivity Framework.

Community
  • 1
  • 1
  • 1
    This problem has already been solved? – Kosuke Ogawa Oct 30 '15 at 12:55
  • @KosukeOgawa Is this a question or a statement? I am seeking for solutions so if you have link to a solution, I'd appreciate it a lot. – Gunnar Torfi Steinarsson Oct 31 '15 at 10:54
  • What other objects are giving you the "Undefined Symbols" error message? – joern Oct 31 '15 at 12:21
  • It's called Tip.m, Group.m and Tipster.m. The Tip object contains an instance of both Group and Tipster. But those two don't have any custom objects. – Gunnar Torfi Steinarsson Nov 02 '15 at 08:12
  • Does the class Tip conform to the NSCoding protocol? It's not clear that it does, and the error message indicates otherwise. – Owen Hartnett Nov 11 '15 at 16:44
  • Thanks for the response mate, I appreciate it a lot. I'm afraid it does, every single property within the class is encoded and decoded. Every property that its type is an object, has it's properties encoded and decoded as well. Little bit about the question itself. How come it's only 1 up? I put a lot of work in the question and have to say it's pretty clear and researched. – Gunnar Torfi Steinarsson Nov 12 '15 at 21:00
  • Just to make sure - Class Tip has the two methods: initWithCoder and encodeWithCoder? – Owen Hartnett Nov 16 '15 at 21:27
  • Yes and every variable (property) in the Tip class, that is a custom object, has these two functions as well (and is encoding/decoding their properties). – Gunnar Torfi Steinarsson Nov 18 '15 at 16:42

2 Answers2

1

I solved this temporarily by using didReceiveMessage (the NSDictionary version instead of the NSData).

I sent a manually created NSDictionary of a single NSArray that held regular NSStrings of my previous custom objects.

0

I have the same scenario and reached the same problem. After some searching (without any luck) and experimenting, I've solved it by adding the -all_load flag to the linker flags in the extension target.

fcardoso
  • 76
  • 2