Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26339] iOS: Local notification not triggered when setting repeat (only 7.3.0.GA)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-08-29T06:43:37.000+0000
Affected Version/sRelease 7.3.0
Fix Version/sRelease 7.3.1
ComponentsiOS
Labelsios, notifications
ReporterTeun Klijn
AssigneeHans Knöchel
Created2018-08-27T13:37:36.000+0000
Updated2018-11-07T09:26:22.000+0000

Description

I've noticed that local push notifications won't be shown when setting the repeat property, it does show when it's omitted. This seems to have started with SDK 7.3.0.GA. Example:
var win = Ti.UI.createWindow({
  backgroundColor: "white",
  layout: "vertical"
});

var repeatSwitch = Ti.UI.createSwitch();

var btn = Ti.UI.createButton({
  top: 50,
  title: "Schedule"
});

btn.addEventListener("click", function() {
  var not = {
    date: new Date(new Date().getTime() + 3000),
    alertTitle: 'Notification',
    alertBody: 'This is a notification',
    badge: 1,
    userInfo: {
      id: '1'
    },
    repeat: repeatSwitch.value ? "daily" : undefined
  };

  console.log('schedule: ' + JSON.stringify(not));

  Ti.App.iOS.scheduleLocalNotification(not);
});

win.add(btn);
win.add(Ti.UI.createLabel({
  text: "Repeat?"
}));
win.add(repeatSwitch);

win.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
    ]
  });
});

win.open();

Attachments

FileDateSize
TiAppiOSProxy.m2018-08-28T12:02:08.000+000050508

Comments

  1. Hans Knöchel 2018-08-27

    Hey there! We refactored the whole notifications-API to use the new UserNotifications framework in iOS 10+. Your issue sounds valid and we'll provide a fix for this early this week. Thank you!
  2. Hans Knöchel 2018-08-28

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10289 PR (7_4_X): https://github.com/appcelerator/titanium_mobile/pull/10291 PR (7_3_X): https://github.com/appcelerator/titanium_mobile/pull/10290 Test-Case: Above [~teunklijn@telfort.nl] Can you please do me a favor and replace the attached [^TiAppiOSProxy.m] in the following directory:
       ~/Library/Application Support/Titanium/mobilesdk/osx/7.3.0.GA/iphone/Classes/TiAppiOSProxy.m
       
    You can make a backup of the old file to be sure. Let me know if it works properly now! Spontaneously, I didn't find a way to test if the notification will be triggered 24 hours later, but the new code looked good :-).
  3. Teun Klijn 2018-08-28

    The attached TiAppiOSProxy.m seems to be identical to the one that I already have, so the notification doesn't trigger yet. I've tried the one from the pull request, but that also doesn't trigger. I could have used the wrong one.
  4. Hans Knöchel 2018-08-28

    [~teunklijn@telfort.nl] Sorry, try again. It was the old one from an earlier Git revision.
  5. Teun Klijn 2018-08-28

    It does work better now, the notification does trigger if you schedule only 1, but if you schedule 2 notifications in a row only the 2nd notification will appear. It doesn't matter if you set repeat or not, for example:
       var win = Ti.UI.createWindow({
         backgroundColor: "white",
         layout: "vertical"
       });
       
       var repeatSwitch = Ti.UI.createSwitch();
       
       var btn = Ti.UI.createButton({
         top: 50,
         title: "Schedule"
       });
       
       btn.addEventListener("click", function() {
         var not = {
           date: new Date(new Date().getTime() + 3000),
           alertTitle: 'Notification',
           alertBody: 'This is a notification 1',
           badge: 1,
           userInfo: {
             id: '1'
           },
           repeat: repeatSwitch.value ? "daily" : undefined
         };
       
         console.log('schedule: ' + JSON.stringify(not));
       
         Ti.App.iOS.scheduleLocalNotification(not);
       
         not = {
           date: new Date(new Date().getTime() + 6000),
           alertTitle: 'Notification',
           alertBody: 'This is a notification 2',
           badge: 1,
           userInfo: {
             id: '1'
           },
           repeat: repeatSwitch.value ? "daily" : undefined
         };
       
         console.log('schedule: ' + JSON.stringify(not));
       
         Ti.App.iOS.scheduleLocalNotification(not);
       });
       
       win.add(btn);
       win.add(Ti.UI.createLabel({
         text: "Repeat?"
       }));
       win.add(repeatSwitch);
       
       win.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
           ]
         });
       });
       
       win.open();
       
  6. Hans Knöchel 2018-08-28

    That probably happens because the default identifier is used if not explicitly set. I noticed that this only happens for the new UserNotifications framework on iOS 10+, so it may be an Apple bug or per design. A simple fix is to assign different identifier strings to make them unique. This also helps to better manage pending / delivered notifications. *EDIT*: Confirmed to work with the following:
       var win = Ti.UI.createWindow({
         backgroundColor: "white",
         layout: "vertical"
       });
        
       var repeatSwitch = Ti.UI.createSwitch();
        
       var btn = Ti.UI.createButton({
         top: 50,
         title: "Schedule"
       });
        
       btn.addEventListener("click", function() {
         var not = {
           date: new Date(new Date().getTime() + 3000),
           alertTitle: 'Notification',
           alertBody: 'This is a notification 1',
           badge: 1,
           identifier: '1',
           userInfo: {
             id: '1'
           },
           repeat: repeatSwitch.value ? "daily" : undefined
         };
        
         console.log('schedule: ' + JSON.stringify(not));
        
         Ti.App.iOS.scheduleLocalNotification(not);
        
         not = {
           date: new Date(new Date().getTime() + 6000),
           alertTitle: 'Notification',
           alertBody: 'This is a notification 2',
           identifier: '2',
           badge: 1,
           userInfo: {
             id: '1'
           },
           repeat: repeatSwitch.value ? "daily" : undefined
         };
        
         console.log('schedule: ' + JSON.stringify(not));
        
         Ti.App.iOS.scheduleLocalNotification(not);
       });
        
       win.add(btn);
       win.add(Ti.UI.createLabel({
         text: "Repeat?"
       }));
       win.add(repeatSwitch);
        
       win.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
           ]
         });
       });
        
       win.open();
       
  7. Teun Klijn 2018-08-28

    That does indeed work! Thank you for your help.
  8. Hans Knöchel 2018-08-28

    I just pushed another commit to make notifications on iOS 10+ unique by default, to match the iOS < 10 behavior for now. It internally generates a UUID-string that is also injected into the "userInfo.id" if not already set, so it can be used to identifier them later again. Does that match your expectations of the API?
  9. Teun Klijn 2018-08-28

    Yes that does match my expectations.
  10. Samir Mohammed 2018-08-29

    Verified fix in SDK version 7.5.0.v20180828231421 and 7.3.1.v20180828234519. *Test Steps FR*

    Created a new titanium project

    Added the code from the description in to the application

    Ran the program

    Enabled scheduled push notifications

    Pressed schedule

    Went to the home screen

    Able to see the push notifications trigger

    Created a new application with the second test case in the comments

    followed the steps above (3-7)

    Able to see both notifications trigger

    *Test Environment*
        APPC Studio:  5.1.0.201808080937
        APPC CLI: 7.0.6-Master.5
        iphone 6 simulator (11.2)
        iphone 6 simulator (9.3)
        Operating System Name: Mac OS High Sierra
        Operating System Version: 10.13.6
        Node.js Version: 8.9.1
        Xcode 10.0 beta 6
        
    *Note:* Waiting for the 7_4_X build from Jenkins.
  11. Samir Mohammed 2018-08-29

    *Closing Ticket* Verified fix in SDK Version 7.4.0.v20180829012158 With the above steps.
  12. David van de Meer 2018-11-07

    Hi, it seems like this has now broken the scheduling of local notification when you DO NOT set "repeat" The code below will never fire the notification
        	// The following code snippet schedules an alert to be sent within three seconds
        	var notification = Ti.App.iOS.scheduleLocalNotification({
        		category: "TEST",
        		alertAction: 'Read now',
        		alertBody: 'Custom message',
        		date: new Date(new Date().getTime() + 30000),
        		//repeat: "never",
        		//The following URL is passed to the application
        		userInfo: {
        			"task": "test2"
        		}
        	});
        
  13. David van de Meer 2018-11-07

JSON Source