Search code examples
cordovaionic-frameworkuilocalnotificationios10ngcordova

Listener '$cordovaLocalNotification:trigger' not triggered where as '$cordovaLocalNotification:scheduled' is working


This is ionic(Not ionic v2) with angularjs. When a local notification is scheduled, I see '$cordovaLocalNotification:schedule' getting triggered but not '$cordovaLocalNotification:trigger'.

   $rootScope.$on('$cordovaLocalNotification:schedule',
        function (event, notification, state) {
            // ...
            alert("Local Notification scheduled");
        });

    $rootScope.$on('$cordovaLocalNotification:trigger',
        function (event, notification, state) {
            // ...
            alert("Local Notification triggered")
        });

Providing the methods below using which notifications are triggered:

$rootScope.scheduleNotification = function (title,notificationMessage) {
    $cordovaLocalNotification.schedule({
      id: 1,
      title: title,
      text: notificationMessage,
      data: {
        customProperty: 'custom value'
      }
    }).then(function (result) {
      // ...
    });
  }; 

All the injections are set and I presume without that scheduled listener will not work!


Solution

  • After googling found that, tweaking of existing plugin katzer/cordova-plugin-local-notifications is necessary to support iOS 10 changes to Push Notification & LocalNotifications to support the new Notification center features.

    As a temporary fix, do the below:

    1. ionic plugin rm de.appplant.cordova.plugin.local-notification
    2. ionic plugin add https://github.com/spk0611/cordova-plugin-local-notifications#9ad32cf2059cdf9a54b4930b1c58ba76ef7e3a87
    3. Go to Xcode and ensure that XCode -> Preferences -> Locations and check if Command Line Tools is set to Xcode 8.(I am really not aware why this is done)
    4. while in Xcode, go to the build settings for your target and be certain “Enable Modules (C and Objective-C)” is turned on
    5. finally, edit plugin.xml (it’s in the plugins folder of the added one) to uncomment the line that commented out the cordova-plugman engine in order for the app to actually have access to the plugin.

    add plugin from here

    Solution Source

    And Hurray! I got it working :-)