I am making an Apple Watch app. One of the buttons will open the iphone app connected to the watch app.
What code do I use to do this?
I don't know what to even try?
Note: I am using swift for this project.
I am making an Apple Watch app. One of the buttons will open the iphone app connected to the watch app.
What code do I use to do this?
I don't know what to even try?
Note: I am using swift for this project.
WatchKit doesn't include the ability to open the host iOS app in the foreground. The best you can do is open it in the background using openParentApplication:reply:
.
If you need the user to do something in your iOS app, consider making use of Handoff.
It is not possible to activate an inactive iPhone app from the Watch. It is, however, possible to call the iPhone app to perform a task or to ask for data. See here: Calling parent application from Watch app
You can only open the iPhone app in the background by the following method:
Swift:
openParentApplication([ParentApp], reply:[Reply])
Objective-C:
openParentApplication:reply:
There is no ability to open the parent app in the foreground.
Note: To send data to iOS app in the background, use the first method.
Note: According to bgilham,
If you need the user to do something in your iOS app, consider making use of Handoff.
If you need to open your parent app in the foreground, use Handoff!
https://developer.apple.com/handoff/
Example:
Somewhere shared for both:
static let sharedUserActivityType = "com.yourcompany.yourapp.youraction"
static let sharedIdentifierKey = "identifier"
on your Watch:
updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil)
on your iPhone in App Delegate:
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
}
And finally (this step is important!!!): In your Info.plist(s)