1
votes

I'm currently trying to build an app for Android and iOS which should be able to send local notifications to the user.

I have managed to send local notifications on Android but I'm unable to get it working on iOS.

When I start the app on iOS 9 then the iPhone shows a prompt which asks me to allow the app to send notifications. After allowing the app to send notifications there is still no notification.

On Android: Start App -> Notification with text "OK"

On iOS 9: Start App -> Allow to send notifications -> no notification

I also tried to add a button to the app which triggers Notifier.notify('test') but this didn't work.

I even created new Apple certificates and provisioning profiles.

I'm using this plugin: https://github.com/katzer/cordova-plugin-local-notifications

and also tried this one: https://build.phonegap.com/plugins/4859

I'm building the app using the PhoneGap Build service.

Does anyone have an idea why it works on Android but not on iOS?

My code:

config.xml:

...
<plugin name="cordova-plugin-local-notifications-mm"/>
...

index.html:

<script src="cordova.js"></script>
<script src="local-notification.js"></script>
<script src="js/index.js"></script>
<script src="js/notify.js"></script>

index.js:

var app = {
    initialize: function () {
        this.bindEvents();
    },
    bindEvents: function () {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    onDeviceReady: function () {
        Notifier.registerPermission();
    }
};
app.initialize();

notify.js:

var Notifier = {
    registerPermission: function () {
        window.plugin.notification.local.registerPermission(function (granted) {
            Notifier.notify('OK');
        });
    },
    notify: function (message) {
        var now = new Date();
        window.plugin.notification.local.add({
            id: parseInt(new Date().getTime()),
            message: message,
            date: now
        });
    }
};
1
please let us know if you find a solution to this!ezabaw

1 Answers

0
votes

Just finished an ibeacon app that works on both ios and android with notifications even when app is closed or phone is restarted.

Make sure to add:

cordova.plugins.locationManager.requestAlwaysAuthorization();

That is what did it for me.