Search code examples
iospush-notificationapple-push-notificationsappceleratorappcelerator-titanium

Appcelerator iOS push notification displaying in foreground


Currently using the following to handle push notifications os iOS devices.

Ti.App.iOS.addEventListener("usernotificationsettings", function registerForPush() {

    Ti.App.iOS.removeEventListener("usernotificationsettings", registerForPush);

    Cloud.Users.login({
        login: "user",
        password: "12345"
    }, function (e) {

        if (e.success) {

           Ti.Network.registerForPushNotifications({
                success: function(e){

                    Cloud.PushNotifications.subscribeToken({
                        channel: "AppAlerts",
                        device_token: e.deviceToken,
                        type: "ios"
                    }, function(e){
                        alert("subscribed");
                    });

                },
                error: function(e){
                    alert(e.error);
                },
                callback: function(e){
                    alert(e);
                }
            });

         }
    }); 

});

I am able to register device tokens without any problems to Appcelerator. When the app is in the background and the user clicks on a push notification the callback is called and I am able to read the payload. However while the app is in the foreground the notification banner is displayed (as if the app was still in the background). The callback is never called when clicking on the banner or when received.

Example

This seems to happen on devices with iOS 10+. A device with 9.3.5 had no problems.


Solution

  • I managed to get this working by building the app with Titanium SDK 7.2.0 GA. The app previously used 7.3.1 GA and 7.4.0 GA.