Swift : Passing data to Apple Watch app.

Today`s post will basically cover how to transfer/send basic data from iPhone application to apple Watch Application.

There are different ways to passing data from apple watch application to iPhone application.

The one solution is that NSUserdefaults. and another is using HandleWatchKitExtensionRequest and openParentApplication method.

The openParentApplication is a class method, so this method actually be called from the WKInterfaceController class itself.

when WatchKit Extension calls WKInterfaceController.openParentApplication that means it passes to info dictionary to parent iPhone application. which the iPhone application can return the info dictionary data and that data we can use that for our requirement. one important thing is the providing data has been serialized.

InterfaceController.swift

AppDelegate.swift

so, when we see openParentApplication called inside the button clicked event, this indicates that the replay from the iPhone application has been received.