Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当有人点击Apple Watch应用程序时,如何打开该应用程序?_Ios_Xcode_Swift_Watchkit_Apple Watch - Fatal编程技术网

Ios 当有人点击Apple Watch应用程序时,如何打开该应用程序?

Ios 当有人点击Apple Watch应用程序时,如何打开该应用程序?,ios,xcode,swift,watchkit,apple-watch,Ios,Xcode,Swift,Watchkit,Apple Watch,我正在制作一个苹果手表应用程序。其中一个按钮将打开连接到watch应用程序的iphone应用程序 我使用什么代码来执行此操作 我都不知道该试什么 注意:我正在使用swift进行此项目。WatchKit不包括在前台打开主机iOS应用程序的功能。您最好在后台使用openParentApplication:reply:打开它 如果你需要用户在你的iOS应用程序中做一些事情,考虑使用切换。 不可能从手表中激活一个不活跃的iPhone应用程序。但是,可以通过调用iPhone应用程序来执行任务或请求数据。请

我正在制作一个苹果手表应用程序。其中一个按钮将打开连接到watch应用程序的iphone应用程序

我使用什么代码来执行此操作

我都不知道该试什么


注意:我正在使用swift进行此项目。

WatchKit不包括在前台打开主机iOS应用程序的功能。您最好在后台使用
openParentApplication:reply:
打开它


如果你需要用户在你的iOS应用程序中做一些事情,考虑使用切换。

不可能从手表中激活一个不活跃的iPhone应用程序。但是,可以通过调用iPhone应用程序来执行任务或请求数据。请参见此处:

您只能通过以下方法在后台打开iPhone应用程序:

斯威夫特:

openParentApplication([ParentApp], reply:[Reply])
目标C:

openParentApplication:reply:
无法在前台打开父应用程序

注意:要在后台将数据发送到iOS应用程序,请使用第一种方法

注:根据bgilham的说法

如果你需要用户在你的iOS应用程序中做一些事情,考虑使用切换。


如果需要在前台打开父应用程序,请使用切换

示例

两者共享的地方:

static let sharedUserActivityType = "com.yourcompany.yourapp.youraction"
static let sharedIdentifierKey = "identifier"
在您的手表上:

updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil)
在您的iPhone应用内代理上:

func application(application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {
    if (userActivityType == sharedUserActivityType) {
        return true
    }
    return false
}

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool {
    if (userActivity.activityType == sharedUserActivityType) {
        if let userInfo = userActivity.userInfo as? [String : AnyObject] {
            if let identifier = userInfo[sharedIdentifierKey] as? Int {
                //Do something
                let alert = UIAlertView(title: "Handoff", message: "Handoff has been triggered for identifier \(identifier)" , delegate: nil, cancelButtonTitle: "Thanks for the info!")
                alert.show()
                return true
            }
        }
    }
    return false
}
最后(这一步很重要!!!):在你的Info.plist中


什么是交接。请详细说明?@nachshonfertel这里有一些关于交接的信息;你应该自己搜索一下。有没有办法在iphone上打电话?@nachshonfertel在互联网上搜索一下。显示一些努力。@nachshonfertel在评论中有一个链接,从这里开始。所以不是在这里牵着你的手走的每一步。