Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

push.on('notification') callback is not called on coldstart on iOS #758

Closed
addityasingh opened this issue Mar 29, 2016 · 3 comments
Closed

Comments

@addityasingh
Copy link

Expected Behaviour

The callback push.on('notification') should be called on coldstart on iOS

Actual Behaviour

The callback push.on('notification') is not called on coldstart on iOS

Reproduce Scenario (including but not limited to)

Steps to Reproduce

  1. Open your app on iOS
  2. Register for PN
  3. Put the app in background
  4. Trigger a PN
  5. PN successfully arrives and on tapping on it the notification callback will be called.
  6. Close the app
  7. Trigger a PN again
  8. Tap on the PN
  9. The notification callback will not be called now

    Platform and Version (eg. Android 5.0 or iOS 9.2.1)

    iOS 9.1

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Cordova CLI version and cordova platform version

cordova --version                                    6.0.0
cordova platform version ios                     4.0.1

Plugin version

cordova plugin version | grep phonegap-plugin-push   1.6.0

Sample Push Data Payload

Sample Code that illustrates the problem

Logs taken while reproducing problem

@addityasingh addityasingh changed the title notification callback is not called on coldstart on iOS push.on('notification') callback is not called on coldstart on iOS Mar 29, 2016
@addityasingh addityasingh reopened this Mar 29, 2016
@addityasingh
Copy link
Author

I have found the solution for this one. The reason for this issue is that in PushPlugin.m the callbackId property is set to nil on killing the app. As a result, the check on line#441 is not satisfied in the - (void)notificationReceived callback. The fix for the issue is to instantiate the PushPlugin class on opening the push notification every time your app starts. This can be done by registering the push notification plugin on app start.
Call the PushPlugin.init method in your javascript everytime your app starts, and this will instantiate the plugin and assign the appropriate callback and callbackid in the plugin. I have added the below code to my Ionic app's app.run() section

window.PushNotification.init({ 
    ios: {
       "badge": false,
       "sound": true,
       "alert": true,
       "clearBadge": true
   }
})

Let me know if anyone still faces this issue.

@dickverweij
Copy link

If placed in app.run() is window.PushNotification defined? (we dont have to wait for device.ready?)

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants