phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

Push Plugin initializes but the on('registration') or on('error') never fires on iOS only (works in Android) #2841

Open SurfaceRock opened 4 years ago

SurfaceRock commented 4 years ago

Expected Behaviour

Hi hopefully someone out there can help me. I've been working on this issue for a few days. My push-plugin was working just a week ago for iOS, but now it doesn't get the device token I need to Register it with APNS.

I don't know what happened, I know I recently updated ionic-cli@latest and I updated cordova from 8.1.2 to 9.9.0 but I reverted back and it still doesn't work so I'm not sure if that did anything.

The Push Plugin initializes and on('registration') should fire but it doesn't the on('error') doesn't fire either.

This is the only error I see in the logs, but I'm not using FCM for push I am using APNS.

2019-10-22 16:21:02.828338-0600 Surface Rock Technologies[401:71296] [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add[FIRApp configure];(FirebaseApp.configure()in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8. 2019-10-22 16:21:02.830 Surface Rock Technologies[401] <Error> [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add[FIRApp configure];(FirebaseApp.configure()in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

(Push Plugin still works & registers a device in Android, just not iOS)

Anyways been up till 3 in the morning for the last 2 nights trying different builds, I have no idea what I did wrong to have the Push Plugin all of a sudden stop working.

[I remember I did try to install at the beginning phonegap-launch-navigator but I removed that earlier.]

Hopefully someone can help me, thanks in advance!

Actual Behaviour

Push Plugin initializes but the on('registration') never fires.

Reproduce Scenario (including but not limited to)

Using Ionic 4 app

npm uninstall -g cordova npm install -g cordova ( tried w/ v9.0.0, 8.1.2, 8.1.1 )

ionic cordova plugin rm phonegap-plugin-push Ionic cordova platform rm ios Ionic cordova platform add ios ionic cordova plugin add phonegap-plugin-push@2.3.0 --variable SENDER_ID=XXX --variable FCM_VERSION=16.0.9

npm install --save @ionic-native/push@5.15.1

ionic cordova build ios

Open Xcode -> Run on connected Device (Tried on 3 iphones on iOS 12.2 & 12.4.2 and 12.4.1)

Plugin List

cordova plugin list cordova-background-geolocation 3.3.0 "BackgroundGeolocation" cordova-plugin-actionsheet 2.3.3 "ActionSheet" cordova-plugin-background-fetch 5.6.1 "CDVBackgroundFetch" cordova-plugin-cocoalumberjack 0.0.4 "CocoaLumberjack" cordova-plugin-device 2.0.3 "Device" cordova-plugin-dialogs 2.0.2 "Notification" cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 4.1.1 "cordova-plugin-ionic-webview" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-support-google-services 1.3.1 "cordova-support-google-services" phonegap-plugin-multidex 1.0.0 "Multidex" phonegap-plugin-push 2.3.0 "PushPlugin"

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

cordova-ios@5.0.1 (Tried on 3 iphones on iOS 12.2 & 12.4.2 and 12.4.1)

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

Android is working by the way.

Cordova CLI version and cordova platform version

cordova --version                               Tried with v9.0.0 & v8.1.2 & v7*

Plugin version

cordova plugin version | grep phonegap-plugin-push  2.3.0

Sample Push Data Payload

Sample Code that illustrates the problem

Here's the service I am using:

` import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Device } from '@ionic-native/device/ngx'; import { Push, PushObject, PushOptions } from '@ionic-native/push/ngx'; import { SrtApiService } from './srt-api.service'; import { environment } from 'src/environments/environment';

@Injectable({ providedIn: 'root' }) export class PushService {

constructor( public http: HttpClient, public push: Push, public device: Device, private mainApi:SrtApiService ) { }

regObj = { registrationId: null, registrationType: null };

// Push Service Should be Initialized after user Login. init () { const options: PushOptions = { android: { senderID: environment.fcm_sender_id }, // ios: { // sound: true, // vibration: true, // badge: true // }, };

const pushObject: PushObject = this.push.init(options)

pushObject.on('registration').subscribe((registration: any) => {
    console.log("PushObject->registration:" ,registration);
    // registration = {
    //   registrationId: "czdM_EaOpFg:APA91bH4VgrF79hnmdJADO...-"
    //   registrationType: "FCM"
    // }

    this.regObj = registration;
    let params = {
      reg_id: registration.registrationId,
      type: registration.registrationType,
      platform: this.device.platform,
      model: this.device.model,
      uuid: this.device.uuid
    }

    // Have to send this data to rails. & register it. 
    this.mainApi.postData( 'api/v1/devices', params ).subscribe( (res:any)=>{
      console.log( "PushService->on('registration'): ", res );
    });

});

pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));

} } `

Logs taken while reproducing problem

`

2019-10-22 16:21:02.128608-0600 Surface Rock Technologies[401:71072] Apache Cordova native platform version 5.0.1 is starting. 2019-10-22 16:21:02.129887-0600 Surface Rock Technologies[401:71072] Multi-tasking -> Device: YES, App: YES 2019-10-22 16:21:02.162806-0600 Surface Rock Technologies[401:71072] CDVWKWebViewEngine: trying to inject XHR polyfill 2019-10-22 16:21:02.307784-0600 Surface Rock Technologies[401:71072] CDVWKWebViewEngine will reload WKWebView if required on resume 2019-10-22 16:21:02.308151-0600 Surface Rock Technologies[401:71072] Using Ionic WKWebView 2019-10-22 16:21:02.309892-0600 Surface Rock Technologies[401:71072] [CDVTimer][console] 0.164032ms 2019-10-22 16:21:02.310223-0600 Surface Rock Technologies[401:71072] [CDVTimer][handleopenurl] 0.149965ms 2019-10-22 16:21:02.318019-0600 Surface Rock Technologies[401:71072] [CDVTimer][intentandnavigationfilter] 7.548094ms 2019-10-22 16:21:02.318586-0600 Surface Rock Technologies[401:71072] [CDVTimer][gesturehandler] 0.141025ms 2019-10-22 16:21:02.319009-0600 Surface Rock Technologies[401:71072] [CDVTimer][backgroundfetch] 0.128984ms 2019-10-22 16:21:02.319519-0600 Surface Rock Technologies[401:71072] CDVIonicKeyboard: resize mode 1 2019-10-22 16:21:02.330902-0600 Surface Rock Technologies[401:71072] [CDVTimer][keyboard] 11.375904ms 2019-10-22 16:21:02.347426-0600 Surface Rock Technologies[401:71072] [CDVTimer][splashscreen] 15.836000ms 2019-10-22 16:21:02.369973-0600 Surface Rock Technologies[401:71072] [CDVTimer][statusbar] 21.084070ms 2019-10-22 16:21:02.370670-0600 Surface Rock Technologies[401:71072] [CDVTimer][TotalPluginStartup] 61.074972ms 2019-10-22 16:21:02.522828-0600 Surface Rock Technologies[401:71072] active 2019-10-22 16:21:02.526225-0600 Surface Rock Technologies[401:71072] PushPlugin skip clear badge 2019-10-22 16:21:02.828338-0600 Surface Rock Technologies[401:71296] [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add [FIRApp configure]; (FirebaseApp.configure() in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8. 2019-10-22 16:21:02.830 Surface Rock Technologies[401] [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add [FIRApp configure]; (FirebaseApp.configure() in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8. 2019-10-22 16:21:10.581652-0600 Surface Rock Technologies[401:71072] Ionic Native: deviceready event fired after 7060 ms 2019-10-22 16:21:10.583987-0600 Surface Rock Technologies[401:71072] AppComponent->platforms(): iphone,ios,cordova,mobile,hybrid 2019-10-22 16:21:10.614476-0600 Surface Rock Technologies[401:71072] AppComponent->user received: 2019-10-22 16:21:10.623474-0600 Surface Rock Technologies[401:71072] AppComponent->authSubject: 2019-10-22 16:21:10.633714-0600 Surface Rock Technologies[401:71072] AppComponent->Unfollow Channel... false 2019-10-22 16:21:11.080893-0600 Surface Rock Technologies[401:71072] setting user data: UserService.user [object Object] 2019-10-22 16:21:11.082471-0600 Surface Rock Technologies[401:71072] Home->user received: [object Object] 2019-10-22 16:21:11.083713-0600 Surface Rock Technologies[401:71072] AppComponent->user received: [object Object] 2019-10-22 16:21:11.084838-0600 Surface Rock Technologies[401:71072] subscribing to user.channel user_dzB4JoyL05g3bUvkOavAVw 2019-10-22 16:21:11.108386-0600 Surface Rock Technologies[401:71072] UserService->Authorizing User Roles: plant-driver 2019-10-22 16:21:11.109210-0600 Surface Rock Technologies[401:71072] UserService->Required Roles: admin 2019-10-22 16:21:11.118000-0600 Surface Rock Technologies[401:71072] WARN: UserService->Redirecting User: Unauthorized for this page, required roles: admin 2019-10-22 16:21:11.118696-0600 Surface Rock Technologies[401:71072] UserService->nagivateToRole: plant-driver 2019-10-22 16:21:11.122744-0600 Surface Rock Technologies[401:71072] Push Plugin VoIP missing or false 2019-10-22 16:21:11.123957-0600 Surface Rock Technologies[401:71296] Push Plugin register called 2019-10-22 16:21:11.124110-0600 Surface Rock Technologies[401:71296] PushPlugin.register: setting badge to false 2019-10-22 16:21:11.124184-0600 Surface Rock Technologies[401:71296] PushPlugin.register: clear badge is set to 0 2019-10-22 16:21:11.124326-0600 Surface Rock Technologies[401:71296] PushPlugin.register: better button setup 2019-10-22 16:21:11.124912-0600 Surface Rock Technologies[401:71296] FCM Sender ID (null) 2019-10-22 16:21:11.126359-0600 Surface Rock Technologies[401:71296] Using APNS Notification

`

antonioballesteros commented 4 years ago

I understand that is only an error in some test you are doing, but you have commented the IOS definition

// ios: { // sound: true, // vibration: true, // badge: true // }, };

I've arrived here with the same problem but other configuration, cordova + react webapp

iamnotapenguin commented 4 years ago

I have the same issue. New app setup, just trying to test out. Just using the download of phonegap desktop with the sample push notification template that's built in. Works great with android and windows. On ios, registration never happens and push.on error isn't called either. Tried rolling back the plugin version in config.xml, tried adding a .p8 auth key to app folder. Tried a few other things but none of it can so much as generate an error for me.

ghost commented 4 years ago

Hi. Same issue here. Any solution?

iamnotapenguin commented 4 years ago

Hi. Same issue here. Any solution?

Just to follow up, no solution but I did iron out a few more things that weren't the problem as near as I can tell. As I'm testing with a version of the phonegap developer app for ios that I had built myself using the adobe build tutorial, I wanted to make sure there wasn't something on the provisioning profile side that I had missed that may be standing in the way. I saw that I hadn't generated a certificate for push development when creating the developer app. So, I corrected that and made a new profile and rebuilt the app. Still nothing. No dialog asking if notifications are ok. Never gets any further than trying to register and getting apparently no reply. I've tried it now with an iphone and an ipad, and with multiple computers running the desktop app. I figured this would be an easy one since it's one of the templates that comes with the desktop app. Will keep working on it. It's good to know I'm not the only one - please update me here if you figure anything out.

ghost commented 4 years ago

I am sure that all the certificates and profiles are ok. The pushObject.on('registration') was working perfect until I updated the plugin to the 2.3.0 version

SurfaceRock commented 4 years ago

I understand that is only an error in some test you are doing, but you have commented the IOS definition

// ios: { // sound: true, // vibration: true, // badge: true // }, };

I've arrived here with the same problem but other configuration, cordova + react webapp

I solved my issue a while back, but I wasn't sure exactly which of the 2 things I did solved it.

  1. I listened to antonioballesteros reply above and I was commenting out the ios configuration, so I un-commented.

  2. I was building the App with and "Apple Distribution" Provisioning Profile, I made a new "iPhone Distribution" Provisioning profile and re-created the certificates on apple. (Although I swear it was working at one point for Apple Push Notifications, I may have had the settings previously on 'Automatic manage signing' - I'm not 100% sure.)

So I'm not sure if it was the un-commenting of the ios configuration that fixed it, or having Xcode build with the iPhone Distribution Provisioning Profile.

Hope this helps!

iamnotapenguin commented 4 years ago

Just to add a follow up to SurfaceRock's excellent post about this problem, along with the provisioning profile another huge help for me in solving this problem was to make sure that Adobe Build was using a cli greater than 6.5. Changing my project config to use a newer cli than the default made notifications start working like regular. More information in the comments of this issue: https://github.com/phonegap/phonegap-plugin-push/issues/2201

infuzz commented 4 years ago

Hi, after years without any issue, I suddenly facing the same issue: on('registration') and on('error') never fires on IOS 13.3.0 and 13.3.1. Everything works very well on Android 9 & 10.

The notification auth prompt pop up well on first launch, but after Accepting, nothing else happens.

phonegap push plugin 2.3.0 cli 9.0.0 Phonegap IOS 5.0.1 Settings : ios: { sound: true, vibration: true, badge: true }

I have recreated all cert and profile, to be sure there is no issue with that, but it doesn't change the issue. Does anybody have the same issue since today ? Please HELP )-;

EDIT: 2 hours later : I have absolutely no explanation but it is now working without ANY modification !!!! (I don't touch my code during lunch time (-; !!! ) Maybe an issue on apn side ??? Does somebody else experiment this kind of issue ?

daveed80 commented 4 years ago

Hi,

I'm experiencing a similar issue with droid (OS v9, samsung galaxy S9). After calling PushNotification.init, the dialog to allow or deny notifications is never presented. Also, the PushNotification.hasPermission returns true after calling init, without having allowed push notifications.

Has anyone seen the same and/or made progress with a solution?

daveed80 commented 4 years ago

To follow up, all events seem to be working. In fact, push.on("registration" is firing, is receiving a valid registration id from FCM, and I'm able to send notifications and have them received on the device successfully.

PushNotification.init just never invokes/displays the allow/deny prompt to give the user the ability to allow or deny receiving notifications....

gpowerone commented 4 years ago

So, in case you are like me and you said "it doesn't work" because you didn't wait at least 30 seconds for the registration results - you do need to wait for the registration results.

itismelito commented 4 years ago

I have the same issue. It used to work perfect before. All the sudden not anymore. For me it shows permission dialog and after this step nothing happens it hangs in there. No error no response. On android it works just fine. Anyone knows a solution?

vilhelmjosander commented 4 years ago

Same issue here for me. The 'registration' event suddenly stopped working after updrading to version 2.3.0 and push-plugin.

I had to update since 2.2.3 (old version) sends malformed registrationId due to changes in iOS 13. All certificates and profiles are OK. Has anyone been able to solve this?

Output from XCode:

2020-04-16 13:22:52.360987+0200 Sakerhetscenter[18026:3582944] Push Plugin VoIP missing or false
2020-04-16 13:22:52.361550+0200 Sakerhetscenter[18026:3583137] Push Plugin register called
2020-04-16 13:22:52.361635+0200 Sakerhetscenter[18026:3583137] PushPlugin.register: setting badge to false
2020-04-16 13:22:52.361690+0200 Sakerhetscenter[18026:3583137] PushPlugin.register: clear badge is set to 0
2020-04-16 13:22:52.361742+0200 Sakerhetscenter[18026:3583137] PushPlugin.register: better button setup
2020-04-16 13:22:52.361960+0200 Sakerhetscenter[18026:3583137] Using APNS Notification

But the 'registration' event is never fired.

infuzz commented 4 years ago

So sorry, No explanation, I had never found why sometime it fails... iOS is really a mess, difficult to dev, stress to submit app (even if we pay for that... no garantee), to notify... Tech should be predictive... Each input make the same output, but with iOS, no, everything is changing each time. I'm tired of this company that compromise each day our futur.... I can't understand dev that are in love of ios. I'm waiting for ios pwa notification support to definitively quit ios dev.... but they could never support it... as usual...