Group Group Group Group Group Group Group Group Group

watchOS - Chapter 16 Watch Connectivity

#1

Been battling with this for hours how - I have an existing Objective C application and I’m trying to add an iWatch application in Swift. I only have the simulator available - and I can’t get even a simple data transfer to work.

Does anyone have any experience with Phone Objective C to Watch Swift Connectivity working - ideally an example?

Head is being to hurt from hitting it against a brick wall.

Thanks.

#2

Hi @alexonit

There shouldn’t be any problems between connecting the obj c and swift code. Can you please specify what exactly are your struggling with? Are there compile errors, crashes?
Here is a link to a related question, maybe it will be useful - https://stackoverflow.com/questions/29572731/i-have-an-objective-c-application-on-ios-how-do-i-build-a-swift-watch-extensio

Nikita

#3

iPhone Objective-C in AppDelegate :

NSError *error;
if ( [WCSession isSupported])
{
    NSDictionary *movies = @{@"key1":@"Eezy"};
    wcSession = [WCSession defaultSession];
    if ([wcSession isWatchAppInstalled])
    {
        [wcSession updateApplicationContext:movies error:&error];

iWatch Swift - In ExtensionDelegate

extension ExtensionDelegate: WCSessionDelegate {

func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {

    print("ExtensionDelegate:didReceiveApplicationContext got here")

Some Debugging shows
ExtensionDelegate:setupWatchConnectivity:WCSession.isSupported
WC Session activated with state: activated

#4

No error messages.
iOS says
AppDelegate:sendDataToWatch:isPaired
AppDelegate:sendDataToWatch:isReachable
AppDelegate:sendDataToWatch:isSupported
AppDelegate:sendDataToWatch:isWatchAppInstalled

iWatch says
ExtensionDelegate:setupWatchConnectivity:WCSession.isSupported
WC Session activated with state: activated
ExtensionDelegate:IsReachable:true

Nothing is being triggered on the iWatch to say data is being received.

#5

Changed it to [wcSession transferUserInfo:xyz]; and it all started working.