watchkit,iOS在手表和iphone之间发送数据

use*_*278 0 objective-c nsnotifications nsnotificationcenter ios watchkit

我想在手表中创建一个按钮,同时点击手表启动一个进程到我的ios应用程序.如何在两台设备之间发送数据

-(void)viewWillAppear:(BOOL)animated

{
 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(sayHello:) name: @"sayHelloNotification" object: nil];

}
Run Code Online (Sandbox Code Playgroud)

 [[NSNotificationCenter defaultCenter] postNotificationName: @"sayHelloNotification" object: nil];
Run Code Online (Sandbox Code Playgroud)

在我的按钮手表,但它不起作用

Wes*_*ton 10

如果要将数据发送到父应用,请使用.

[WKInterfaceController openParentApplication:userInfo reply:^(NSDictionary *replyInfo, NSError *error){}];
Run Code Online (Sandbox Code Playgroud)

在您的监视应用程序中调用此方法将触发AppDelegate中的回调

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply;
Run Code Online (Sandbox Code Playgroud)

您必须在发送的userInfo字典中定义数据.

  • 有没有办法反过来?就像我了解如何让ios应用程序获得像位置这样的东西,但是你如何将响应发送回watchkit应用程序?目前我正在更新NSUserDefaults但是没有办法让watchkit应用程序知道更新发生了. (3认同)