One Signal Problem

Hi, I installed the One Signal plugin and I’m creating a page for notification settings. I can not access the getPermissionSubscriptionState method.

I pass correctly in costructor

private _SIGNAL : OneSignal

and then

 this._PLATFORM.ready()
		.then(() =>
		{  
			this.triggerNotification();
		});

In the method i configure options like this

this._SIGNAL.startInit(......)
this._SIGNAL.inFocusDisplaying(this._SIGNAL.OSInFocusDisplayOption.InAppAlert);

	  

      // Retrieve the OneSignal user id and the device token
      this._SIGNAL.getIds()
      .then((ids) =>
      {
		 this.storage.set('player_id', ids.userId);
         console.log('getIds: ' + JSON.stringify(ids));
		 this.locationTracker.startTracking(ids.userId);
      });


      // When a push notification is received handle
      // how the application will respond
      this._SIGNAL.handleNotificationReceived()
      .subscribe((msg) =>
      {
         // Log data received from the push notification service
         console.log('Notification received');
         console.dir(msg);
      });


      // When a push notification is opened by the user
      // handle how the application will respond
      this._SIGNAL.handleNotificationOpened()
      .subscribe((msg) =>
      {
         // Log data received from the push notification service
         console.log('Notification opened');
         console.dir(msg);
      });
	  
	  this._SIGNAL.getPermissionSubscriptionState()
	  .then((msg) {
			console.log(JSON.stringify(msg));
	  });
      // End plugin initialisation
      this._SIGNAL.endInit();

but this is not working :getPermissionSubscriptionState

I do not understand why :sob:

Property ‘getPermissionSubscriptionState’ does not exists on type ‘OneSignal’

global packages:

    @ionic/cli-utils : 1.4.0
    Cordova CLI      : 6.5.0
    Ionic CLI        : 3.4.0

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.4.0
    @ionic/cli-plugin-ionic-angular : 1.3.1
    Cordova Platforms               : android 6.1.2
    Ionic Framework                 : ionic-angular 3.4.2

System:

    Node       : v6.7.0
    OS         : Windows 7
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 3.10.3

I’ve installed the latest plugin

Any ideas?

Tell us what “OneSignal”/_SIGNAL is in your code.

_SIGNAL is the name of the Onesignal plugin instance, like platform or others:

constructor(private storage: Storage, public navCtrl: NavController, private _PLATFORM : Platform, private _SIGNAL : OneSignal) {
	  this._PLATFORM.ready()
		.then(() =>
		{  
			this.triggerNotification();
		});

  }

Ah sure, now my crystal ball can tell me if this method you are calling is actually present in the plugin. Or if it really works. Or how it works.
Oh wait, I lost my crystal ball this morning.
(Please provide a link and a version you are using)

Also: Where and how are you testing?

2 Likes

I’m using the latest version of the plugin:

onesignal-cordova-plugin 2.1.2 “OneSignal Push Notifications”

I’m using the command ‘ionic serve’ and i receive the compilation error listed above .

Before adding this, i tried the application on android device and i’m able to receive notification.

The method getPermissionSubscriptionState is listed in documentation:

https://documentation.onesignal.com/docs/cordova-sdk#section–getpermissionsubscriptionstate-

I’m new with Ionic and angular JS :slight_smile:

All the functionality will only work on devices, no with ionic serve.

Obviously, but i receive a compilation problem, during transpile. If I execute the command ‘ionic cordova run android’ , it exit

C:\Cremona_Circuit>ionic cordova run android --verbose
[DEBUG] Loading global plugin @ionic/cli-plugin-proxy
[DEBUG] Throwing PLUGIN_NOT_INSTALLED for global @ionic/cli-plugin-proxy
[DEBUG] Loading local plugin @ionic/cli-plugin-cordova
[DEBUG] Loading local plugin @ionic/cli-plugin-ionic-angular
Running app-scripts build: --address 0.0.0.0 --port 8100 --p 8100 --livereload-p
ort 35729 --r 35729 --iscordovaserve --externalIpRequired --nobrowser

[16:45:24]  build dev started ...
[16:45:24]  clean started ...
[16:45:24]  clean finished in 30 ms
[16:45:24]  copy started ...
[16:45:24]  transpile started ...
[16:45:30]  typescript: C:/Cremona_Circuit/src/pages/home/home.ts, line: 89
            Property 'getPermissionSubscriptionState' does not exist on type 'On
eSignal'.

      L89:  this._SIGNAL.getPermissionSubscriptionState()
      L90:  .then((msg)  =>

[WARN] Error occurred during command execution from a CLI plugin
       (@ionic/cli-plugin-cordova). Your plugins may be out of date.
[DEBUG] !!! ERROR ENCOUNTERED !!!
Error: Failed to transpile program
[DEBUG] Error: Failed to transpile program
        at BuildError.Error (native)
        at new BuildError
        (C:\Cremona_Circuit\node_modules\@ionic\app-scripts\dist\util\errors.js:
16:28)
        at
        C:\Cremona_Circuit\node_modules\@ionic\app-scripts\dist\transpile.js:137
:20
        at transpileWorker
        (C:\Cremona_Circuit\node_modules\@ionic\app-scripts\dist\transpile.js:10
3:12)
        at Object.transpile
        (C:\Cremona_Circuit\node_modules\@ionic\app-scripts\dist\transpile.js:61
:12)
        at buildProject
        (C:\Cremona_Circuit\node_modules\@ionic\app-scripts\dist\build.js:97:78)

        at
        C:\Cremona_Circuit\node_modules\@ionic\app-scripts\dist\build.js:47:16


Are you sure the OneSignal you are using isn’t https://ionicframework.com/docs/native/onesignal/? The way your code looks like normally isn’t used for Cordova plugins alone…

Yes, it is. The One signal plugin is inside an ionic app. And the method getPermissionSubscriptionState is listed inside the documentation

Please post your package.json content and ionic cordova plugin list output.
Also show the import of OneSignal.

package.json

{
  "name": "Cremona_Circuit",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.1.3",
    "@angular/compiler": "4.1.3",
    "@angular/compiler-cli": "4.1.3",
    "@angular/core": "4.1.3",
    "@angular/forms": "4.1.3",
    "@angular/http": "4.1.3",
    "@angular/platform-browser": "4.1.3",
    "@angular/platform-browser-dynamic": "4.1.3",
    "@ionic-native/background-geolocation": "^3.12.1",
    "@ionic-native/core": "3.10.2",
    "@ionic-native/facebook": "^3.12.1",
    "@ionic-native/geofence": "^3.12.1",
    "@ionic-native/geolocation": "^3.12.1",
    "@ionic-native/in-app-browser": "^3.12.1",
    "@ionic-native/onesignal": "^3.12.1",
    "@ionic-native/splash-screen": "^3.10.2",
    "@ionic-native/status-bar": "^3.10.2",
    "@ionic-native/youtube-video-player": "^3.12.1",
    "@ionic/storage": "2.0.1",
    "ionic-angular": "3.4.2",
    "ionicons": "3.0.0",
    "rxjs": "5.4.0",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.7",
    "@ionic/cli-plugin-cordova": "1.4.0",
    "@ionic/cli-plugin-ionic-angular": "1.3.1",
    "typescript": "2.3.3"
  },
  "description": "An Ionic project"
}

ionic cordova plugin list:

> cordova plugin ls
? Running command - done!
cordova-plugin-add-swift-support 1.6.2 "AddSwiftSupport"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-facebook4 1.9.1 "Facebook Connect"
cordova-plugin-geofence 0.7.0 "geofence"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-mauron85-background-geolocation 2.2.5 "CDVBackgro
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-plugin-youtube-video-player 1.0.6 "CordovaYoutubeVideoPl
es6-promise-plugin 4.1.0 "Promise"
ionic-plugin-keyboard 2.2.1 "Keyboard"
onesignal-cordova-plugin 2.1.2 "OneSignal Push Notifications"

One Signal import on file home.ts

import { OneSignal } from '@ionic-native/onesignal';
1 Like

Ok, so you ARE using Ionic Native.

3.12.1 is the current version, so your library should match the current documentation.
The code for that method exists on the plugin: https://github.com/ionic-team/ionic-native/blob/master/src/@ionic-native/plugins/onesignal/index.ts#L582

So why isn’t this working for you… hmm…

So I found out that the docs for [quote=“AntonioCC, post:1, topic:94981”]
getPermissionSubscriptionState
[/quote] are not correct, and opened an issue about it: https://github.com/ionic-team/ionic-native/issues/1710 But that has nothing to do with your error.

Could you replace getPermissionSubscriptionState with foobar and tell me the error message?

I’m pretty much out of ideas here…

[10:06:41]  build started ...
[10:06:41]  transpile update started ...
[10:06:41]  transpile update finished in 40 ms
[10:06:41]  deeplinks update started ...
[10:06:41]  deeplinks update finished in 40 ms
[10:06:41]  webpack update started ...
[10:06:46]  typescript: C:/Cremona_Circuit/src/pages/home/home.ts, line: 89
            Property 'foobar' does not exist on type 'OneSignal'.

      L89:  this._SIGNAL.foobar()
      L90:  .then((msg) =>
1 Like

Okay, so exact same error message.

Can you look into /node_modules/@ionic-native/onesignal if the getPermissionSubscriptionState is in there (as it should be)?

I found something… inside folder node_modules/@ionic-native/onesignal and file index.js, there’s no reference of getPermissionSubscriptionState method … why??

Same no reference inside index.d.ts

So, no reference in both files

Instead here

https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/onesignal/index.ts

the method is present

Hmm, I can confirm - downloading the current @ionic-native release doesn’t contain the method.

Seems it was added not too long ago: https://github.com/ionic-team/ionic-native/commit/e9283a994db483dd0959b85284f08b565eccfe34

I think you should open an issue with ionic-native on Github and describe the problem. Probably a broken release somehow. (Inlcude a link to here as well and post the issue link here too)

Ohhh… the docs is for the unreleased plugin! There wasn’t a release for 16 days, the method was added after that. So somehow newer docs got released, but not the new version of the code.

Ok, many many thanks!!! I’m waiting an update of ionic native code

Any updates?
I need to use this method for a toggle enable/disable subscription.
Any ideas to make a toggle without getPermissionSubscriptionState are appreciated …