Ionic can't find variable applewatch

Hi,

I’m trying to use the cordova-plugin-apple-watch (GitHub - leecrossley/cordova-plugin-apple-watch: Cordova / PhoneGap Apple Watch Plugin for Apache Cordova), but i’ve some problems. Just with the init code:

applewatch.init(function (appGroupId) { // success, messages may now be sent or listened for }, function (err) { // an error occurred }, "group.com.mycompany.watch");

I’ve the error message:

Can’t find variable: applewatch

I’ve check, my plugin is in my project.
I’ve removed and install the plugin but that change nothing…

If anyone has a idea thank’s!

I’ve had this problem when I didn’t call my plugin after $ionicPlatform.ready()
can you try to wrap your code into it ?
I have never used applewatch, but this could work.

Thank’s for your help!

I’ve try this:

`$ionicPlatform.ready(function() {
        if(window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if(window.StatusBar) {
            StatusBar.styleDefault();
        }
                         
        applewatch.init(function (appGroupId){
             applewatch.sendMessage("Test test!", "myqueue");
        }, function(err) {
                                         
       },
      "group.com.*****.watch");
        
    });
`

And now I’ve got this:

ReferenceError: Can’t find variable applewatch

Nobody can help me? I’ve tried to add the field cordova_plugins.js to my index.html but that change nothing…

How did you install your plugin ?
Can you manage to have another plugin working ?
Is your plugin present in the package.json file ?

I’ve use the command: ionic plugin add cordova-plugin-apple-watch
And I’ve cordova-plugin-screen-orientation installed and I can use it.

I only have this for plugins in my package.json:
"cordovaPlugins": [ "com.ionic.keyboard", "cordova-plugin-inappbrowser" ]

How can m’y screen orientation work…

If you do a "cordova plugin list" ?

I got this:

com.ionic.keyboard 1.0.4 “Keyboard”
cordova-plugin-app-version 0.1.8 “AppVersion”
cordova-plugin-apple-watch 0.11.3 “Apple Watch”
cordova-plugin-crosswalk-webview 1.0.0 “Crosswalk WebView Engine”
cordova-plugin-inappbrowser 1.2.0 “InAppBrowser”
cordova-plugin-screen-orientation 1.4.0 “Screen Orientation”
cordova-plugin-whitelist 1.0.0 “Whitelist”

Last thing, could you execute an “ionic info” ?

Sure:

Cordova CLI: 6.0.0
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.0
Ionic Version: 1.1.0
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
ios-deploy version: 1.8.4
ios-sim version: 5.0.6
OS: Mac OS X El Capitan
Node Version: v4.2.4
Xcode version: Xcode 7.2.1 Build version 7C1002

I just tried to add the plugin to my App.
1- cordova plugin add cordova-plugin-apple-watch
2- the plugin is not present either in my package.json file
3- I put the init function in my app.js, in .run, in $ionicPlatform.ready()
4- The output is OK (no plugin undefined, just a bad config on apple-watch plugin)

I didn’t inject any particular dependency except $ionicPlatform.
I have the same info on my ionic, ecept npm 4.3.1.

Ok tell me if it works. :slight_smile:

Just edited my post, sorry :wink:

You put the init in this?

.run(function($ionicPlatform, $rootScope) {
 
    $ionicPlatform.ready(function() {
        applewatch.init(function (appGroupId) {
            // success, messages may now be sent or listened for
            applewatch.sendMessage("Bonjour tout le monde", "myqueue");
        }, function (err) {
            // an error occurred
        },
        "group.com.mycomp");
        
    });
})

You test with ionic serve or emulate?

Exactly like this yeah.
Maybe you can try to remove and add your plugin again

I tried with emulate, and on device

How can i have the output/debug message with emulate?
I try --consolelogs but that doesn’t work. :confused:

I use Xcode to emulate, by just clicking the run button.

image

After that, i have my console output in Xcode.

If you are not on iOS, i think you can do ionic emulate <ios/android> -l -c

I think my error message was because I launch the app with ionic serve…
I’m gonna try to add a WatchKit to my project.

Thank’s for your help

Keep me in touch of how it goes,
I’m glad I could help.

@JC_cap Hi, sorry for the late answer I wasn’t in my office last week.
So, I’ve try with the simulator (iPhone et Apple Watch) and I didn’t have error message! Thank’s for your help.

Now I’ve to understand how that works. ^^

EDIT:
@JC_cap Do you know how can I have the debug for the two application in XCode? I only have th debug for the watchkitExtension.