将图像从iPhone传递到Apple Watch无法正常工作

时间:2015-05-29 20:16:47

标签: ios objective-c iphone apple-watch

关于传递图像的大多数教程都谈论现有图像。我试图在iPhone上运行时生成图像并传递给Apple Watch。

我使用MMWormhole作为SO Question引用,但是没有通过我的图像。

我现在尝试直接在+ openParentApplication上使用WKInterfaceController。我收到一个错误:

Property list invalid for format: 200 (property lists cannot contain NULL)

我看一下,看看UIImage无法序列化。所以现在我尝试转换UIImage > NSData > NSString并发送

- (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);
    }

1 个答案:

答案 0 :(得分:0)

您需要在两端指定应用组ID。像:

MMWormhole *wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:appGroupId optionalDirectory:kWormholeDirectory];