繁体   English   中英

如何从WatchKit应用程序在iPhone上打开应用程序?

[英]How can I open the application on iPhone from my WatchKit app?

我在应用程序中使用watchkit。 我想通过watchkit在iPhone中打开应用程序。我进行了很多搜索,但找不到任何东西。 任何帮助将不胜感激。

我还尝试了以下链接如何从WatchKit应用程序在iPhone上打开父应用程序?

如果使用Objective C,则只需将以下方法放入AppDelegate.m文件中。

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
    NSString * request = [userInfo objectForKey:@"requestString"];
    if ([request isEqualToString:@"executeMethodA"]) {
        // Do whatever you want to do when sent the message. For instance...
        //[self executeMethodABC];
    }
    reply(@{@"clicked from  watch":@(1)});
}

我希望这能帮到您。

实施方法

您应该在AppDelegate文件中实现接收消息方法( application:handleWatchKitExtensionRequest:reply )。

斯威夫特:AppDelegate.swift

let message = userInfo.objectForKey("message") as! NSString
if message.isEqualToString("launchApp") {
    //Launch functions here
}

Objective-C:AppDelegate.m

NSString* message = [userInfo objectForKey:@"message"];
if ([message isEqualToString:@"launchApp"]) {
    // Launch functions here
}

结论

1-您应该在应用程序委托中实现接收消息的方法。

2-在Swift中,应用程序委托是AppDelegate.swift

3-在Obj-C中,应用程序委托是AppDelegate.m

4-接收消息的方法是application:handleWatchKitExtensionRequest:reply

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM