情况:我openParentApplication在Watch应用程序handleWatchKitExtensionRequest中使用主应用程序.这在模拟器中运行良好,当iPhone应用程序处于活动/打开状态时,它也适用于实际设备(Apple Watch和iPhone).
问题:当我在实际设备(Apple Watch和iPhone)上运行它时,如果主iPhone应用程序未处于活动/打开状态,handleWatchKitExtensionRequest则不会返回数据openParentApplication.
WatchKit扩展中的InterfaceController.m中的代码:
NSDictionary *requst = @{ @"request" : @"getData" };
[InterfaceController openParentApplication:requst
reply:^( NSDictionary *replyInfo, NSError *error ) {
// do something with the returned info
}];
Run Code Online (Sandbox Code Playgroud)
iPhone主应用程序的app代理中的代码:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void ( ^)( NSDictionary * ))reply
{
if ( [[userInfo objectForKey:@"request"] isEqualToString:@"getData"] )
{
// get data
// ...
reply( data );
}
}
Run Code Online (Sandbox Code Playgroud)