-7

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.

Ashley Mills
  • 44,005
  • 15
  • 120
  • 151
nachshon fertel
  • 135
  • 1
  • 1
  • 11

4 Answers4

1

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.

bgilham
  • 5,849
  • 1
  • 23
  • 39
0

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

Community
  • 1
  • 1
vomako
  • 8,350
  • 5
  • 34
  • 59
0

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.

Seyyed Parsa Neshaei
  • 3,450
  • 20
  • 29
0

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)

enter image description here

stk
  • 5,923
  • 10
  • 40
  • 54