Ionic push notifications only appear in the background on iOS 10


#1

I’ve probably read ~ 50 posts on this topic, but none which seem to address the particular problem I’m having. While using Cordova’s push plugin using FCM and APNS, I’ve come across a problem where ALL push notifications to my iPhone appear as banner notifications. So far, I’ve:

  1. Created new ionic 2 project.
  2. Added to ionic.io
  3. Added phonegap-plugin-push plugin (with sender ID for Android, set up in FCM)
  4. Created Apple development certificate
  5. Created Apple push notification development SSL certificate
  6. Created Apple provisioning profile (development) - my iPhone device already registered
  7. Ionic.io - created development security profile, uploaded APN credentials, iOS app build credentials)
  8. ionic run android (on local device just to test - works perfect, push registers fine).
  9. Enabled Push Notifications in the Capabilities tab in XCode. All indications tell me that this feature is set up properly.
  10. ionic cordova build ios --debug, then run on iPhone via XCode

On Android phones and on iOS devices < iOS 10.0, the alerts show up more or less as expected. On iOS >= 10, I only get the banner notification like the app is in the background. Here is the code I have written:

in app.module.ts:

const cloudSettings: CloudSettings = {
  'core': {
    'app_id': 'APP_ID'
  },
  'push': {
    'sender_id': 'SENDER_ID',
    'pluginConfig': {
      'ios': {
        'badge': true,
        'sound': true
      },
      'android': {
        'iconColor': '#343434'
      }
    }
  }
};

@NgModule({
  declarations: [
    [all my amazing declarations
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(myApp),
    IonicStorageModule.forRoot(myApp),
    CloudModule.forRoot(cloudSettings),
    HttpModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    [all my fun pages]
  ],
  providers: [
    [All my providers]
  ]
})
export class AppModule {}

And in app.component.ts:

initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.

        this.statusBar.overlaysWebView(false);
        this.statusBar.styleLightContent();
        this.splashScreen.hide();

        this.initPush();
    });
  }

initPush() {
    //JJC Use this string to check the environment, enable/disable native app features
    this.push.register().then((t: PushToken) => {
      console.log('Token generated: ' + t.token);
      return this.push.saveToken(t);
    }).then((t: PushToken) => {
      console.log('Token saved:', t.token);      
    }).catch((e:Error) => console.log(e));

    this.push.rx.notification()
      .subscribe((msg) => {
        alert(msg.text);
      }, ((err: any) => console.log('Notification did not work: ' + err)));
  }

Is there a problem with how I’m handling the data, or is there some step I’ve missed in setting up APNS? When looking at the console, the APNS token is being generated and saved properly, and again it works fine on iOS < 10.0. Any help would be appreciated.

EDIT: here is a screenshot of the notification. The app open is indeed the application for which the notification was meant, but it should be showing as an alert.


#2

Please post a screenshot of the notification as you see it.


#3

I ran into similar behaviour recently, except that it was on an android phone. Push notification did not trigger the code in this.push.rx.notification().subscribe(...), but instead, I noticed a new notification in the top bar (small app icon, not even a banner). When the app was closed or in background, the push notification was displayed as usual.

I was not able to fix this directly. Instead, I realised that this strange behaviour disappears after I upload a new snapshot (Ionic Deploy service) and install the app through App-/Play-Store (and let it automatically update to the newest snapshot).

How are you running the app on your device? Through a store or via CLI (ionic cordova run ios ...)?
Are you using Ionic Deploy, too?


#4

Not using Ionic Deploy, simply building it with ionic cordova build ios --args and running it in XCode. We currently have it on Test Flight, and it’s showed the same behavior so far; luckily the requirements for the push functionality aren’t very complex, otherwise we’d be in trouble at this stage.

We’ll be uploading a new version in the next few days so I can see if there’s any change, but I doubt it; again, this works fine in iOS < 10.