How to pass UIImage from iPhone app to Apple Watch app

十年热恋 提交于 2019-12-01 01:12:50
Dejan Skledar

Yes it is. All you need to do is create a NSDictionary like:

var dict:[NSString : UIImage] = ["image" : yourImage]

And then you just use the following methods to communicate between the Apple Watch and the iOS app: LINK

The answers here are only half correct cause you can't send an UIImage directly! You need to send your images as NSData like f.e. so:

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo
              reply:(void (^)(NSDictionary *))reply
{
  reply(@{@"image" : UIImagePNGRepresentation(yourUIImage)});
  // JPEG Representation would of course also work
}

Yes you can do.

You can pass data using this method

- (IBAction)passUserInfo:(id)sender
{
    NSDictionary *userInfo = @{@"image":[UIImage imageNamed:@"test"]};

    [WKInterfaceController openParentApplication:userInfo reply:^(NSDictionary *replyInfo, NSError *error){
        if ([replyInfo objectForKey:@"success"]) {
            NSLog(@"Sent your data");
        }
    }];// userinfo must be non-nil
}

and you can handle your data in this method.

    - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
    UIImage *image = [userInfo objectForKey:@"image"];

    NSDictionary *replyInfo = @{@"success":@"success",@"error":@""};

    reply(replyInfo);
}

Otherwise see this Tutorial

MMWormhole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!