Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

ios - Apple Watch, WatchKit Extension and main application

There is main application with logic and we extend app to Apple Watch.

After adding target xCode creates 2 more applications: extension with code and watch kit application.

Question: How code from extension can reuse logic of ready and already made main iOS app? How extension app can communicate with main App and send commands.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To communicate to the containing iPhone app you can use

(BOOL)openParentApplication:(NSDictionary *)userInfo
                        reply:(void (^)(NSDictionary *replyInfo,
                                        NSError *error))reply

In your WKInterfaceController

From the Apple Docs

Use this method to communicate with your containing iOS app. Calling the method causes iOS to launch the app in the background (as needed) and call the application:handleWatchKitExtensionRequest:reply: method of its app delegate. That method has the following signature:

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo
reply:(void(^)(NSDictionary *replyInfo))reply

The app delegate receives the dictionary you pass into the userInfo parameter and uses it to process whatever request you made. If it provides a reply, WatchKit executes the block you provided in the reply parameter of this method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...