Search code examples
ioscordovaphonegapphonegap-pushplugin

Not receiving PN in iOS release. works fine in development


I am trying to integrate phonegap-plugin-push, but cant seem to get it work in release mode. Cannot receive Push Notification when app is deployed to TestFlight or store. Notification seems to work fine, when in development mode.

I followed the steps to install the Push Plugin as defined here: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md

Platform and Version

iOS 11.2.6

Cordova CLI version

cordova --version
    8.0.0

Cordova platform version

Installed platforms:
    android 7.1.0
    ios 4.5.4

cordova plugin version | grep phonegap-plugin-push # e.g. 1.5.3 phonegap-plugin-push 2.2.2 "PushPlugin"

Sample Push Data Payload

Sending any payload did not work. I tried to send PN from Firebase Console as well as pushtry.com

Logs taken while reproducing problem

These are the logs that I'm able to collect from deployed version using https://www.npmjs.com/package/cordova-plugin-native-logs

Push.init is called once the user logs in.

First Login Attempt - App just installed

2018-04-02 14:01:43.976 [432:123186] [CDVTimer][nativelogs] 0.962973ms
2018-04-02 14:01:43.979 [432:123186] [CDVTimer][TotalPluginStartup] 45.592070ms
2018-04-02 14:01:43.988 [432:123186] createNotificationChecker
2018-04-02 14:01:43.988 [432:123186] coldstart
2018-04-02 14:01:44.463 [432:123186] active
2018-04-02 14:01:44.464 [432:123186] PushPlugin skip clear badge
2018-04-02 14:01:45.353 [432:123186] Ionic Native: deviceready event fired after 296 ms
2018-04-02 14:01:46.926 [432:123186] CDVWKWebViewEngine: handleStopScroll
2018-04-02 14:01:48.191 [432:123186] {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":400,"statusText":"Bad Request","url":"1.0/user-details","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://api.example.com/1.0/user-details: 400 Bad Request","error":{"error":"token_not_provided"}}
2018-04-02 14:02:09.478 [432:123186] -[UIWindow endDisablingInterfaceAutorotationAnimated:] called on <UIRemoteKeyboardWindow: 0x1058ae600; frame = (0 0; 414 736); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x1c4035800>> without matching -beginDisablingInterfaceAutorotation. Ignoring.
2018-04-02 14:02:17.532 [432:123186] CDVWKWebViewEngine: handleStopScroll
2018-04-02 14:02:18.754 [432:123186] this.pages is called
2018-04-02 14:02:18.754 [432:123186] register push called
2018-04-02 14:02:18.763 [432:123186] Push Plugin VoIP missing or false
2018-04-02 14:02:18.764 [432:123216] Push Plugin register called
2018-04-02 14:02:18.764 [432:123216] PushPlugin.register: setting badge to false
2018-04-02 14:02:18.764 [432:123216] PushPlugin.register: clear badge is set to 0
2018-04-02 14:02:18.764 [432:123216] PushPlugin.register: better button setup
2018-04-02 14:02:18.767 [432:123216] FCM Sender ID 16--752--616
2018-04-02 14:02:18.767 [432:123216] Using FCM Notification
2018-04-02 14:02:18.902 [432:123186] FCM token is null
2018-04-02 14:02:18.907 [432:123186] Push Plugin register failed
2018-04-02 14:02:19.266 [432:123186] updating address
2018-04-02 14:02:20.084 [432:123186] active
2018-04-02 14:02:20.084 [432:123186] PushPlugin skip clear badge
2018-04-02 14:02:20.691 [432:123186] The FCM registration token needs to be changed.
2018-04-02 14:02:20.699 [432:123186] FCM Registration Token: cuB6DZDZMxs:APA91bHjReRv-TrwFHxsbVVAj5xeHCh56VhVEDtQ2pcLwWUrcttsA8AkOri-M3TBxXPbnkO9VsFSr1Iqzs6oOYHowx8NlEW4N3MflU5nt678vhwPanGHs4ocnq-KhvWvarSS77g_Efq2
2018-04-02 14:02:22.045 [432:123186] Returning local object of class NSString
2018-04-02 14:02:22.071 [432:123186] THREAD WARNING: ['NativeLogs'] took '47.340088' ms. Plugin should use a background thread.
2018-04-02 14:13:48.080 [432:123642] PBItemCollectionServicer connection disconnected.
2018-04-02 14:13:48.617 [432:123186] active
2018-04-02 14:13:48.617 [432:123186] PushPlugin skip clear badge
2018-04-02 14:13:52.489 [432:123186] {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":400,"statusText":"Bad Request","url":"https://api.example.com/1.0/resident/deregister-device","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://api.example.com/1.0/resident/deregister-device: 400 Bad Request","error":{"errors":{"device_token":["validation.required"]}}}

Log out and Second Login Attempt

2018-04-02 14:13:52.502 [432:123186] updating address
2018-04-02 14:14:11.868 [432:123186] CDVWKWebViewEngine: handleStopScroll
2018-04-02 14:14:13.181 [432:123186] this.pages is called
2018-04-02 14:14:13.182 [432:123186] updating address
2018-04-02 14:14:13.182 [432:123186] register push called
2018-04-02 14:14:13.196 [432:123186] Push Plugin VoIP missing or false
2018-04-02 14:14:13.196 [432:127400] Push Plugin register called
2018-04-02 14:14:13.196 [432:127400] PushPlugin.register: setting badge to false
2018-04-02 14:14:13.196 [432:127400] PushPlugin.register: clear badge is set to 0
2018-04-02 14:14:13.197 [432:127400] PushPlugin.register: better button setup
2018-04-02 14:14:13.201 [432:127400] FCM Sender ID 16--752--616
2018-04-02 14:14:13.201 [432:127400] Using FCM Notification
2018-04-02 14:14:13.206 [432:123186] FCM Registration Token: cuB6DZDZMxs:APA91bHjReRv-TrwFHxsbVVAj5xeHCh56VhVEDtQ2pcLwWUrcttsA8AkOri-M3TBxXPbnkO9VsFSr1Iqzs6oOYHowx8NlEW4N3MflU5nt678vhwPanGHs4ocnq-KhvWvarSS77g_Efq2
2018-04-02 14:14:13.207 [432:123186] Push Plugin register failed
2018-04-02 14:14:13.216 [432:123186] registeration push [object Object]
2018-04-02 14:14:13.764 [432:123186] updating address

More Details

This is my init code

this.push = PushNotification.init({
  android: {
    senderID: '168675298616',
    iconColor: '#488aff',
    clearNotifications: false,
  }
});

this.push.on('registration', (registration) => {
  console.log('registeration push', registration);
  const device = {
    device_token: registration.registrationId,
    device_type: this.platform.is('android') ? 'android' : 'ios'
  };

  this.userService.pushInit(device).subscribe(response => {
    localStorage.setItem('device_token', registration.registrationId);
  }, err => {
    console.log('silently handling registration error. :)');
  });
});

this.push.on('notification', (notification) => {
  console.log("notification", notification);

  let userdata: any = JSON.parse(localStorage.getItem('userData'));
  let addresses: any[] = userdata.member_info.addresses;
  let behaviorAddress = addresses.find(x => x.hoa_id === JSON.parse(notification.additionalData.hoa_id));
  console.log("behaviorAddress", behaviorAddress);

  if (!notification.additionalData.foreground) {
    // Do Something
  }
});

I have Setup Firebase using APNs Authentication Key enter image description here

And this is what capabilities look like:

Xcode: enter image description here

Apple Developer: enter image description here

Whenever I deliver the app through Xcode, I get this email: enter image description here

And as per the email, this is what my "aps-environment" entitlement looks like: enter image description here

Also, I just cannot set aps-environment to production, it just gets set back to development.

Any help in the right direction would be greatly appreciated.


Solution

  • I actually figured this one out. The problem was during build Cordova is referencing incorrect entitlements file.

    The correct entitlements file is located at: /.entitlements, while Cordova is referencing: /Resources/.entitlements

    The one at /Resources does not have aps-environment.

    This is how the Build Settings, look like after cordova build enter image description here