Most tutorials on passing an image talk about existing images. I am attempting to generate images at runtime on the iPhone and pass to the Apple Watch.
I was using MMWormhole
as referenced from SO Question but that didn't get my images through.
I've now tried using + openParentApplication
on WKInterfaceController
directly. I get an error:
Property list invalid for format: 200 (property lists cannot contain NULL)
I look this up and see UIImage cannot be serialized. So now I try to convert UIImage > NSData > NSString
and send
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(loop) userInfo:nil repeats:true];
};
- (void)loop {
[WKInterfaceController openParentApplication:nil reply:^(NSDictionary *replyInfo, NSError *error) {
NSData *m = replyInfo[@"image"];
UIImage *img = [UIImage imageWithData:m];
[self.image setImage:img];
}];
// [self.wormhole passMessageObject:@"hello" identifier:@"hello"];
}
AppDelegate
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {
UIImage *image = [UIImage imageNamed:@"cat.png"];
NSData *data = UIImagePNGRepresentation(image);
NSDictionary *d = @{@"image" : data};
reply(d);
}