Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26594

iOS: Exception when canceling local notifications with removePendingNotifications

    Details

    • Story Points:
      1
    • Sprint:
      2019 Sprint 1

      Description

      I'm trying to cancel local iOS notifications with Ti.App.iOS.UserNotificationCenter.removePendingNotifications(notificationsToCancel), but whenever I try to call this with an array of notifications the app crashes.

      I did a little bit of research and it seems the ENSURE_TYPE on line 109 in TiAppiOSUserNotificationCenterProxy.m throws an exception. But I'm getting the notifications from getPendingNotifications so they should be ok right?

      Example (press schedule and then cancel right afterwards to get the exception):

      var window = Ti.UI.createWindow({
        backgroundColor: 'white'
      });
       
      var button = Ti.UI.createButton({
        title: 'Schedule'
      });
       
      var isScheduling = true;
      button.addEventListener('click', function() {
        if (isScheduling) {    
          var alarmObject = {
            date: new Date(new Date().getTime() + 20000),
            alertBody: "Hello world",
            badge: 1,
            identifier: "test_id",
            sound: 'default'
          };
       
          console.log('schedule: ' + JSON.stringify(alarmObject));
          
          Ti.App.iOS.scheduleLocalNotification(alarmObject);
       
          button.title = "Cancel";
        } else {
          Ti.App.iOS.UserNotificationCenter.getPendingNotifications(function(result) {
            if (result && result.notifications && result.notifications.length) {
              var notificationsToCancel = _.filter(result.notifications, function(n) {
                return n.identifier == "test_id";
              });
       
              console.log('cancel these: ' + JSON.stringify(notificationsToCancel));
       
              if (notificationsToCancel) {
                Ti.App.iOS.UserNotificationCenter.removePendingNotifications(notificationsToCancel);
              }
            }
          });
       
          button.title = "Schedule";
        }
       
        isScheduling = !isScheduling;
      });
       
      window.add(button);
       
      window.addEventListener('open', function() {
        Ti.App.iOS.registerUserNotificationSettings({
          types: [
            Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
          ]
        });
      });
       
      window.open();
      

      Exception:

      [ERROR] The application has crashed with an uncaught exception 'org.testproject.TiAppiOSUserNotificationCenterProxy'.
      [ERROR] Reason:
      [ERROR] Invalid type passed to function
      [ERROR] Stack trace:
      [ERROR] 0   CoreFoundation                      0x000000010f8881bb __exceptionPreprocess + 331
      [ERROR] 1   libobjc.A.dylib                     0x000000010e683735 objc_exception_throw + 48
      [ERROR] 2   TestProject                         0x0000000108c65b1d TiExceptionThrowWithNameAndReason + 141
      [ERROR] 3   TestProject                         0x0000000108c21e7b -[TiProxy throwException:subreason:location:] + 107
      [ERROR] 4   TestProject                         0x0000000108bb1f4f __66-[TiAppiOSUserNotificationCenterProxy removePendingNotifications:]_block_invoke_2 + 1055
      [ERROR] 5   UserNotifications                   0x0000000110bc6161 __111-[UNUserNotificationServiceConnection getPendingNotificationRequestsForBundleIdentifier:withCompletionHandler:]_block_invoke_2.217 + 240
      [ERROR] 6   libdispatch.dylib                   0x0000000110d9c4e1 _dispatch_call_block_and_release + 12
      [ERROR] 7   libdispatch.dylib                   0x0000000110d9d54b _dispatch_client_callout + 8
      [ERROR] 8   libdispatch.dylib                   0x0000000110da401c _dispatch_lane_serial_drain + 720
      [ERROR] 9   libdispatch.dylib                   0x0000000110da4b95 _dispatch_lane_invoke + 455
      [ERROR] 10  libdispatch.dylib                   0x0000000110dad9a8 _dispatch_workloop_worker_thread + 645
      [ERROR] 11  libsystem_pthread.dylib             0x0000000111182fd2 _pthread_wqthread + 980
      [ERROR] 12  libsystem_pthread.dylib             0x0000000111182be9 start_wqthread + 13
      

        Attachments

          Activity

            People

            • Assignee:
              jvennemann Jan Vennemann
              Reporter:
              teunklijn@telfort.nl Teun Klijn
              Reviewer:
              Vijay Singh
              Tester:
              Samir Mohammed
            • Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6729
                  Sync status:
                  PENDING
                  Last received:
                  Last sent:

                  Git Source Code