Search code examples
iosxcodeswiftwatchkit

How can I get the REAL apple watch to open parent application


We have an application that needs to show content on the Apple Watch and with a press open the parent app and display the share view for sharing. This still works on Xcode 6.3 and Simulator 8.3 but on the watch hardware this functionality is broken. Everything else works properly but the parent app will not open unless you manually open it from the phone. The code is simple

Request the parent app from the Apple Watch

    WKInterfaceController.openParentApplication(["SiteName": "DS"],
        reply: { (replyInfo, error) -> Void in
        NSLog("Reply: \(replyInfo)")
    })

Then, in the parent app use this to send a success. This is not called in the actual hardware but it was using the simulator!

    func application(application: UIApplication,
    handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?,
    reply: (([NSObject : AnyObject]!) -> Void)!) {

        if let userInfo = userInfo, request = userInfo["SiteName"] as? String {
            let siteName = userInfo["SiteName"] as? String
            reply(["Message":"Received launch request from \(siteName)"])
            UIApplication.sharedApplication().openURL(NSURL(string: "DSExtension://more")!)
        }

    }

Edit: As a note, this functionality is possible using the actual hardware as you can see when you launch the camera app from the watch. You tap the camera icon on the watch and the camera on the phone will open. Why would Apple lock this out for our apps on the true hardware?


Solution

  • There is no method in WatchKit to open an iPhone app in the foreground from the Watch (other than Handoff). While you can do this in the simulator, it isn't supported on the actual hardware. That's why you're seeing this behavior.