Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

getting error many times t.$OneSignal.isPushNotificationsEnabled is not a function #4

Open
imsidz opened this issue Sep 17, 2019 · 6 comments

Comments

@imsidz
Copy link

imsidz commented Sep 17, 2019

Version

v3.0.0-beta.19

Reproduction link

https://github.com/nuxt-community/pwa-module

Steps to reproduce

i install pwa module to my app normaly with npm i @nuxtjs/pwa @nuxtjs/onesignal use this to my nuxt.config.js

modules: [
  '@nuxtjs/onesignal',
  '@nuxtjs/pwa',
],

// Options
oneSignal: {
  init: {
    appId: 'YOUR_APP_ID', // <- my private key
    allowLocalhostAsSecureOrigin: true,
    welcomeNotification: {
        disable: false
    }
  }
}

and added this to my default.vue layout

mounted() {
    this.$OneSignal.push(() => {
        this.$OneSignal.isPushNotificationsEnabled((isEnabled) => {
        if (isEnabled) {
          this.$OneSignal.getUserId( function(userId) {
              console.log('player_id of the subscribed user is : ' + userId);
              // Make a POST call to your server with the user ID        
          });
        } else {
          console.log('Push notifications are not enabled yet.')
        }
      })
    })
  }

What is expected ?

it should return player_id of the subscribed user is : ' + userId

What is actually happening?

t.$OneSignal.isPushNotificationsEnabled is not a function

Additional comments?

i did try to clear cache and refresh it work first time than again return this error

This bug report is available on Nuxt community (#c170)
@matheuschimelli
Copy link

Have you ever tryed use with async/await? Take a look at: OneSignal Web SDK API

This is the code provided on docs:

OneSignal.push(function() {
  /* These examples are all valid */
  OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled)
      console.log("Push notifications are enabled!");
    else
      console.log("Push notifications are not enabled yet.");    
  });
               
  OneSignal.isPushNotificationsEnabled().then(function(isEnabled) {
    if (isEnabled)
      console.log("Push notifications are enabled!");
    else
      console.log("Push notifications are not enabled yet.");      
  });
});

I can't test locally right now, but i gonna try later using this code:

// enable async function
this.$OneSignal.push(async()=> {
    this.$OneSignal.isPushNotificationsEnabled((isEnabled)=>{
     if (isEnabled)
       console.log("Push notifications are enabled!");
     else
       console.log("Push notifications are not enabled yet.");    
   });
 //use await
 const isPushEnabled = await this.$OneSignal.isPushNotificationsEnabled()
     if (isPushEnabled){
       console.log("Push notifications are enabled!");
    } else {
       console.log("Push notifications are not enabled yet.");      
 }
   });

@buglavecz
Copy link

Hi,

I often get this error too: ReplayCallsOnOneSignal.js:23 TypeError: t.$OneSignal.showNativePrompt is not a function

image

@buglavecz
Copy link

Have you ever tryed use with async/await? Take a look at: OneSignal Web SDK API

This is the code provided on docs:

OneSignal.push(function() {
  /* These examples are all valid */
  OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled)
      console.log("Push notifications are enabled!");
    else
      console.log("Push notifications are not enabled yet.");    
  });
               
  OneSignal.isPushNotificationsEnabled().then(function(isEnabled) {
    if (isEnabled)
      console.log("Push notifications are enabled!");
    else
      console.log("Push notifications are not enabled yet.");      
  });
});

I can't test locally right now, but i gonna try later using this code:

// enable async function
this.$OneSignal.push(async()=> {
    this.$OneSignal.isPushNotificationsEnabled((isEnabled)=>{
     if (isEnabled)
       console.log("Push notifications are enabled!");
     else
       console.log("Push notifications are not enabled yet.");    
   });
 //use await
 const isPushEnabled = await this.$OneSignal.isPushNotificationsEnabled()
     if (isPushEnabled){
       console.log("Push notifications are enabled!");
    } else {
       console.log("Push notifications are not enabled yet.");      
 }
   });

@imsidz it is works?

@P4sca1
Copy link

P4sca1 commented Jan 16, 2020

Might be related to #1 and #3

@pi0 pi0 transferred this issue from nuxt-community/pwa-module Apr 16, 2020
@xdiegom
Copy link

xdiegom commented Aug 3, 2020

Have you ever tryed use with async/await? Take a look at: OneSignal Web SDK API
This is the code provided on docs:

OneSignal.push(function() {
  /* These examples are all valid */
  OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled)
      console.log("Push notifications are enabled!");
    else
      console.log("Push notifications are not enabled yet.");    
  });
               
  OneSignal.isPushNotificationsEnabled().then(function(isEnabled) {
    if (isEnabled)
      console.log("Push notifications are enabled!");
    else
      console.log("Push notifications are not enabled yet.");      
  });
});

I can't test locally right now, but i gonna try later using this code:

// enable async function
this.$OneSignal.push(async()=> {
    this.$OneSignal.isPushNotificationsEnabled((isEnabled)=>{
     if (isEnabled)
       console.log("Push notifications are enabled!");
     else
       console.log("Push notifications are not enabled yet.");    
   });
 //use await
 const isPushEnabled = await this.$OneSignal.isPushNotificationsEnabled()
     if (isPushEnabled){
       console.log("Push notifications are enabled!");
    } else {
       console.log("Push notifications are not enabled yet.");      
 }
   });

@imsidz it is works?

It worked for me 👍🏼, but I refactored this way because logging messages were duplicated:

this.$OneSignal.push(async () => {
  await this.$OneSignal.isPushNotificationsEnabled((isEnabled) => {
    if (isEnabled) console.log('Push notifications are enabled!')
    else console.log('Push notifications are not enabled yet.')
  })
})

Don't really know if this is correct although OneSignal code docs are provided like that 🤔

Nuxt Version: 2.14.0
@nuxtjs/onesignal: 3.0.0-beta.16
@nuxtjs/pwa: 3.0.0-beta.20

@productdevbook
Copy link

Anyone using this library? does it work ? I have the codes giving an error.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants