cordova-plugin-apple-watch icon indicating copy to clipboard operation
cordova-plugin-apple-watch copied to clipboard

Working Sample iOS project

Open redmacdev1988 opened this issue 9 years ago • 5 comments

Hi Lee,

thank you for this plugin. However, I'm running into numerous problems trying to make it work.

For examle, I'm having trouble getting the device and watch to communicate. I'm using UserDefault and its simply not getting the values.

On the app side, the messages are being sent successfully, but I get little issues such as applewatch.init's success function not getting run.

On the Watch Ext side, its not receiving the messages. I'm simply checking the NSUserDefaults with the group name but to no avail.

- (void)willActivate {
//InterfaceController.m
 NSUserDefaults * userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yoyo"];
    [userDefaults synchronize];
    
    NSString * myValue = [userDefaults stringForKey:@"myKey"];
        
    if(myValue) {
        NSLog(@"InterfaceController.m - myValue %@", myValue);
        [self.displayLabel setText:myValue];
    }
    else {
        NSLog(@"myValue is null :(");
        [self.displayLabel setText:@"NULL"];
    }
}

In Staging folder, Staging/www/js/index.js

I have a button where I run:

function sendMessageButtonClicked() {
    
    applewatch.sendUserDefaults(function(){
     console.log('index.js - sendUserDefaults sent to watch');
     },
     function(){
     console.log('index.js - sendUserDefaults failed...');
     },
     { "myKey": "EVIAN" },
     "group.com.yoyo");
}

Anyways, can you offer a sample project on how to get everything to work? It may be a great way to resolve all of my issues and be a help to others.

thank you for your time!

redmacdev1988 avatar Dec 17 '15 08:12 redmacdev1988

I need also a sample project. I also cant get it working, there is no communication between the watch (watchos 2) and app.

patronovski2 avatar Dec 22 '15 08:12 patronovski2

+1 Anybody got any solution

mouryaamit avatar Feb 14 '16 12:02 mouryaamit

Nobody?

patronovski2 avatar Feb 14 '16 14:02 patronovski2

For listening messages from iPhone, it works for me to use watchConnectivityListeningWormhole. listenForMessageWithIdentifier instead of wormhole.listenForMessageWithIdentifier. It's quite strange that wormhole.listenForMessageWithIdentifier only works for initializing the first message, maybe the sample marked in README doesn't conform the Delegate Pattern

jingkecn avatar Apr 26 '16 09:04 jingkecn

as a note to anybody reading this, watchOS2 and on removed the ability to share user defaults across your apps. Essentially, each app owns its own defaults, so if you expect to sendUserDefaults from the iOS app and have them available from the watch, it simply won't work anymore...

http://stackoverflow.com/questions/36050090/reading-nsuserdefaults-in-watchos-2-i-know-app-groups-doesnt-work#answer-36238647

JasonTolliver avatar Dec 01 '16 01:12 JasonTolliver