5

according to OneSignal's site just add this code to ask the user to allow the app to receive push notification :

window.plugins.OneSignal.registerForPushNotifications();

but it doesn't show up. And the device cannot register.

document.addEventListener("deviceready", function() {
            window.plugins.OneSignal.init( "project_id",
                                        {googleProjectNumber: "null_if_ios",
                                        autoRegister: false},
                                        mobile.didReceiveRemoteNotificationCallBack);

For Android, this works just fine. No need to call the registerForNotifications function.

  • 1
    Can you check the device log for any errors when you start your app and when the registerForPushNotifications() function gets called? See [this post](http://stackoverflow.com/questions/24484817/how-to-get-device-console-in-xcode6) to get the full device log. It is best to clear it by clicking the trash can before running your app. Also check to make sure your Provisioning Profile has "Push Notifications" enabled on it by following [Step 5](http://documentation.onesignal.com/v2.0/docs/generating-an-ios-push-certificate#5-provisioning-profiles) in the iOS setup guide. – jkasten May 06 '15 at 21:30

1 Answers1

0

The above code is for a much older version of the OneSignal Cordova SDK, make sure to use the latest version: https://documentation.onesignal.com/docs/cordova-sdk-setup

For Cordova and Cordova variants, many issues can be fixed by checking:

  1. Your OneSignal appID does not have any extra spaces between the quotes.
  2. You are using Cordova 6.4.0 or newer
  3. If using CocoaPods, make sure you have version 1.2.0 or newer installed: https://documentation.onesignal.com/docs/cordova-sdk-setup#section-ios-requirements
  4. You must test on an actual device, not the browser.
  5. Update to the latest version of the OneSignal SDK, run:

cordova plugin rm onesignal-cordova-plugin cordova plugin add onesignal-cordova-plugin

Many users simply need to make a clean build to remove the errors. Please see the Cordova Variants Troubleshooting guide: https://documentation.onesignal.com/docs/troubleshooting-cordova-variants

Finally, checkout the Github example to compare code: Cordova Example: https://github.com/OneSignal/OneSignal-Cordova-Example Ionic Example: https://github.com/OneSignal/OneSignal-Ionic-Example

JonF
  • 554
  • 2
  • 6