Titanium JIRA Archive
Appcelerator Community (AC)

[AC-4516] Ti.App.iOS.scheduleLocalNotification not working with iOS 10

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNot Our Bug
Resolution Date2016-09-28T16:26:19.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsios, ios-10
Reporter Dharshana Jayamaha
AssigneeShak Hossain
Created2016-09-28T02:15:26.000+0000
Updated2016-09-29T03:10:43.000+0000

Description

in iOS 10 scheduleLocalNotification are not working tested bellow code with iOS 9.x and its works as expected. with TI sdk 5.5 and its working but not with iOS 10
// Some comments here
Ti.App.iOS.scheduleLocalNotification({
    date: new Date(new Date().getTime()),
    alertBody: "Hello",
    alertAction: "Re-Launch!",
    badge: 1,
    sound:"pop.caf",  
});

Comments

  1. Hans Knöchel 2016-09-28

    You need to register the notification-settings beforehand, like state din our [guides](http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Local_Notifications). Full example:
       
       // Create notification actions
       var acceptAction = Ti.App.iOS.createUserNotificationAction({
           identifier: "ACCEPT_IDENTIFIER",
           title: "Accept",
           activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
           destructive: false,
           authenticationRequired: true
       });
       
       var rejectAction = Ti.App.iOS.createUserNotificationAction({
           identifier: "REJECT_IDENTIFIER",
           title: "Reject",
           activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
           destructive: true,
           authenticationRequired: false
       });
       
       // Create a notification category
       var downloadContent = Ti.App.iOS.createUserNotificationCategory({
         identifier: "DOWNLOAD_CONTENT",
         actionsForDefaultContext: [acceptAction, rejectAction]
       });    
       
       // Register for user notifications and categories
       Ti.App.iOS.registerUserNotificationSettings({
           types: [
               Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
               Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE,
               Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND
           ],
           categories: [downloadContent]
       });
       
       // Monitor notifications received while app is in the background
       Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
           if (e.category == "DOWNLOAD_CONTENT" && e.identifier == "ACCEPT_IDENTIFIER") {
               Ti.API.warn("start download");
           }
           
           // Reset the badge value
           if (e.badge > 0) {
               Ti.App.iOS.scheduleLocalNotification({
                   date: new Date(new Date().getTime() + 3000),
                   badge: "-1"
               });
           }
           Ti.API.warn(e);
           Ti.API.warn("event: localnotificationaction");
       });
       
       Ti.App.iOS.addEventListener("usernotificationsettings", function(e) {
           Ti.API.warn("event: usernotificationsettings");
       })
       
       // Monitor notifications received while app is in the foreground 
       Ti.App.iOS.addEventListener('notification', function(e) { 
           Ti.API.warn("event: notification");
       });
       
       // App UI
       var win = Ti.UI.createWindow({backgroundColor: 'white'});
       var button = Ti.UI.createButton({title: 'Trigger Notification'});
       
       button.addEventListener('click', function(e){ 
           // Send a notification in 3 seconds
           var note = Ti.App.iOS.scheduleLocalNotification({
               date: new Date(new Date().getTime() + 3000),
               alertTitle: "My download",
               alertSubtitle: "Check it out!",
               alertBody: "New content available! Download now?",
               badge: 1,
               attachments: [{
                   identifier: "my_attachment",
                   url: "default_app_logo.png"
               },{
                   identifier: "my_attachment2",
                   url: "default_app_logo.png"
               }],
               userInfo: {"url": "http://www.download.com/resource/asset.json", id:"1"},
               category: "DOWNLOAD_CONTENT"
           });    
       });
       
       win.add(button);
       win.open();
       
  2. Dharshana Jayamaha 2016-09-29

    @hans Actually i have register the nofitication-settings beforehand. As i mention this issue only in iOS 10. and I also tested code sample you have posted above in iOS 9 and iOS 10 with TI SDK 5.5 result :: iOS 9, I function works as expected. iOS 10, function not working

JSON Source