Table of Content:
- Integrating the Apmetrix iOS (Xcode) SDK into Parent Application
- Setup Parent Application to send and receive Watch messages
- Implementing the WCSessionDelegate method “didReceiveMessage”
Handling Watch Messages in the Parent iOS Application
If your watch application will also be sending application specific messages to your parent application it will be necessary to discern between those messages and messages sent as a result of calls made to the Apmetrix watchOS API, described in Integrating the Apple watchOS SDK. The following simple steps explain what modifications need to be made to the parent application so this is possible.
STEP 1 – Integrating the Apmetrix iOS (Xcode) SDK into Parent Application
Whether you choose to also make calls to the Apmetrix iOS SDK from your parent application or not you will need to add the library to fully process those watch messages that are received as a result of calls to the Apmetrix watchOS API.
NOTE: The revision of the iOS SDK needed to process watch messages from the watchOS SDK is version 2.1.0 or greater. This library is not bundled with the watchOS SDK and therefore must be downloaded separately.
Follow the steps described in Integrating the Apmetrix iOS (Xcode) SDK to add this library to your parent application.
STEP 2 – Setup Parent Application to send and receive Watch messages
If you’re sending watch messages to your parent application then you’ve probably already created a watch connectivity session and added the watch connectivity session delegate.
In brief, the following illustration shows an example of where the AppDelegate is the class that adopts the protocol for the WCSessionDelegate and the watch connectivity session is activated:
STEP 3 – Implementing the WCSessionDelegate method “didReceiveMessage”
It is in the implementation of the watch connectivity session delegate method
that you can discern whether the watch message received was intended for the application or will be handled by the Apmetrix iOS SDK.
Before acting on the message received, pass it as an argument to the Apmetrix SDK’s processWatchMessage API method as illustrated in the figure below. The return value will indicate whether it was processed by the Apmetrix SDK or was ignored, as in the case where the message was intended solely for the application. The returned status value that you want to check for is
If it is desired to check the return from Apmetrix SDK API methods the status value can be returned to the watch via the replyHandler()
See the figure below as an example of how received messages can be handled whether they were intended for the Apmetrix SDK or for the parent application.
This is all that is necessary to handle both application specific messages from the watch and Apmetrix WatchOS messages.