Bappaditya
Bappaditya

Reputation: 9642

iPhone to WatchKit Communication

I am able to send data from Watch to Parent app with

[WKInterfaceController openParentApplication:applicationData reply:^(NSDictionary *replyInfo, NSError *error) {}] 

api but how to send data from iPhone to Watch in Objective C.

Upvotes: 2

Views: 107

Answers (2)

Tiago Almeida
Tiago Almeida

Reputation: 14237

You have some ways to achieve that. The easiest one is using MMWormhole.

You send data using:

[self.wormhole passMessageObject:@{@"titleString" : title} 
                      identifier:@"messageIdentifier"];

and you receive it using:

[self.wormhole listenForMessageWithIdentifier:@"messageIdentifier" 
 listener:^(id messageObject) {
    // Do Something
}];

Note that wormhole uses app groups to communicate, so you need to enable it.

What MMWormhole uses, under the hood, is CFNotificationCenterGetDarwinNotifyCenter. The implementation is simple and if you want to do your own implementation you have more info about CFNotificationCenterGetDarwinNotifyCenter in this medium post.

Upvotes: 2

Halpo
Halpo

Reputation: 3134

Any code executed in your WatchKit Extension is done on your phone, the watch basically acts as sort of external screen

Upvotes: 0

Related Questions