1

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);
    }
Community
  • 1
  • 1
quantumpotato
  • 9,637
  • 14
  • 70
  • 146

1 Answers1

0

You need to specify app group id on both ends. Like:

MMWormhole *wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:appGroupId optionalDirectory:kWormholeDirectory];
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
Joe Smith
  • 1,900
  • 1
  • 16
  • 15
  • So when I set up AppGroups, I still don't get the image coming through – quantumpotato May 29 '15 at 20:39
  • 1
    Let's go one step back, can you pass anything, say a string or a date, with wormhole? I would also suggest you update your question with the new code. The existing code as posted for sure won't work. – Joe Smith May 29 '15 at 20:44
  • Hey Joe, it looks like there was trouble sending UIImage because it cannot be serialized. So now I've tried NSData, edited question. I tried NSDictionary *d = @{@"image" : @"hello"}; reply(d); in App Delegate but same issue (expecting it to send back a string and crash trying to cast as NSData) – quantumpotato May 29 '15 at 20:55
  • Shiiit. I can pass data. I had app groups but didn't have the group *checked* after I created it in Xcode! – quantumpotato May 29 '15 at 21:07
  • I answered a similar question [here](http://stackoverflow.com/questions/30606896/passing-uiimage-from-iphone-to-apple-watch-results-in-nil-response-in-watch/30629865#30629865) for those not using MMWormhole. – Andrew Zimmer Jun 03 '15 at 20:23