Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9481] iOS: cancelLocalNotification on iOS is broken

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2017-05-02T21:41:43.000+0000
Affected Version/sRelease 2.0.2, Release 3.4.0
Fix Version/sRelease 2.1.0, Sprint 2012-12 API
ComponentsiOS
Labelsapi, ios8, module_notification_manager, qe-3.4.0, qe-testadded, regression
ReporterAnirudh Nagesh
AssigneeJon Alter
Created2012-06-11T11:12:10.000+0000
Updated2017-05-02T21:41:43.000+0000

Description

In 'bg.js' of kitchensink, notifications cannot be cancelled using 'id' passed as userinfo dictionary to the notification. {panel:title=bg.js}

var notification = Ti.App.iOS.scheduleLocalNotification({
	alertBody:"Kitchen Sink was put in background",
	alertAction:"Re-Launch!",
	userInfo:{id:"1"},
	sound:"pop.caf",
	date:new Date(new Date().getTime() + 3000) // 3 seconds after backgrounding
});

// we cancel our notification if we don't want it to continue
// notification.cancel(); //this works!!!!


Ti.App.iOS.cancelLocalNotification("1");// this does not work.

This is fixed by Pedro and the fix is available here. https://gist.github.com/48a765c50f64aa7c47ed

Comments

  1. Pedro Enrique 2012-06-13

    Pull Request: https://github.com/appcelerator/titanium_mobile/pull/2383
  2. Blain Hamon 2012-06-13

    Pull merged. Kudos to Pedro.
  3. Michael Pettiford 2012-06-19

    Closing issue Tested with Ti Studio build 2.1.0.201206172244 Ti Mobile SDK 2.1.0.v20120618154152 hash r7830c03d OSX Lion 10.7.3 iPhone 4S OS 5.1 The expected behavior is shown
  4. Satyam Sekhri 2014-09-02

    The cancelLocalNotification is not working on iOS8 device. It works fine for the same build on iOS 7.1 device. Tested On: SDK: 3.4.0.v20140829184521, 3.3.0.GA Studio: 3.4.0.201408291834 CLI: 3.4.0-dev Xcode: Xcode 6 Beta6, XCode5.1.1 Device: iPhone 5S (v8.0), iPhone 4 (v7.1) While testing on iOS 8, the notification sometimes might not come the first time or might take time. On second try it shows the notification despite of cancelLocalNotification
  5. Jon Alter 2014-09-05

    Why aren't we fixing this?

    This is an iOS 8 issue that is easily worked around. When we schedule a notification, it does not immediately show up in the list of scheduled notifications. Because of this, when we call cancelLocalNotification immediately after scheduling a notification, the new notification does not show up in the list of scheduled notifications and therefor can not be cancelled.

    Alternatives

    1. Do not call cancelLocalNotification immediately after scheduling the notification, but set a small timeout first. See the example code below. 2. Call the cancel method no the notification object returned by scheduleLocalNotification.
       var win1 = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff'
       });
       
       var setButton = Titanium.UI.createButton({
       	title:'set',
       	width:500,
       	height:40,
       	top:40
       });
       setButton.addEventListener('click', function()
       {
       
           Ti.App.iOS.registerForLocalNotifications({
               types: Ti.App.iOS.NOTIFICATION_TYPE_SOUND | 
       				Ti.App.iOS.NOTIFICATION_TYPE_ALERT | 
       				Ti.App.iOS.NOTIFICATION_TYPE_SOUND
           });
       
       	var notification = Ti.App.iOS.scheduleLocalNotification({
               alertBody:"Kitchen Sink was put in background",
               alertAction:"Re-Launch!",
               userInfo:{id:"1"},
               date:new Date(new Date().getTime() + 3000) // 3 seconds after backgrounding
           });
       
           // we cancel our notification if we don't want it to continue
           // notification.cancel(); //this works!!!!
       
           setTimeout(function() {
           	Ti.App.iOS.cancelLocalNotification("1");
           }, 500);
       });
       
       win1.add(setButton);
       
       win1.open();
       
  6. Lee Morris 2017-05-02

    Resolving ticket as Invalid as there is now a new version of Kitchen Sink available and we no longer support the version which relates to this ticket.

JSON Source