I have an iPhone app that captures a UIView as UIImage after 5-10 seconds. Is it possible to pass that UIImage to my Apple Watch app and show it in UIImageView there?
Asked
Active
Viewed 1,685 times
1
-
kindly mention the reason for negative votes.. – Muhammad Irfan Apr 08 '15 at 13:18
-
2My guess would be that you didnt bother googling when there are answers already. – Arbitur Apr 08 '15 at 13:23
-
I googled but found answers related to passing strings etc using NSUserDefaults. And it is not recommended to store images in NSUserDefaults – Muhammad Irfan Apr 08 '15 at 13:29
3 Answers
4
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
}

Georg
- 3,664
- 3
- 34
- 75
3
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

Community
- 1
- 1

Dejan Skledar
- 11,280
- 7
- 44
- 70
-
-
Great! You can upvote the LINK answer too, if it was in your help! – Dejan Skledar Apr 08 '15 at 13:29
-
-
0
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

Dharmbir Singh
- 17,485
- 5
- 50
- 66
-
1I have seen it already.. It states "Pass a message with an identifier for the message and a NSCoding compliant object as the message itself" I am afraid that UIImage is not NSCoding complaint, and you have to do some work around to achieve that. So cannot use MMWormhole directly. Thanks for your time Dharmbir – Muhammad Irfan Apr 08 '15 at 14:00