{ "id": "134825", "key": "TIMOB-18182", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "18414", "description": "", "name": "Release 6.2.0", "archived": false, "released": true, "releaseDate": "2017-09-13" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2017-07-20T01:03:41.000+0000", "created": "2014-08-15T21:54:00.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "TCSupport" ], "versions": [ { "id": "15972", "description": "Release 3.4.0", "name": "Release 3.4.0", "archived": false, "released": true, "releaseDate": "2014-09-28" }, { "id": "16676", "description": "Release 3.4.1", "name": "Release 3.4.1", "archived": false, "released": true, "releaseDate": "2014-11-14" } ], "issuelinks": [], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2017-08-10T22:36:59.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "Right now there is no way to determine whether a local notification is received when the app is in the foreground or in the background.\r\n\r\nHere is a sample:\r\n\r\n{code:js}\r\nvar notification = Ti.App.iOS.scheduleLocalNotification({\r\n alertAction: 'Check',\r\n alertBody: 'This is a test',\r\n date: new Date(new Date().getTime() + 3000)\r\n});\r\n\r\nTi.App.iOS.addEventListener('notification', function(e) {\r\n Ti.API.info(JSON.stringify(e));\r\n notification.cancel();\r\n});\r\n{code}\r\n\r\nThe passed-through event object is the same for both situations. However, with remote notification you have such ability: http://docs.appcelerator.com/titanium/latest/#!/api/PushNotificationData-property-inBackground\r\n\r\nFrom Apple's docs, both remote and local notifications are handled similarly. You'll be able to tell whether a local notification is received in the foreground or the background if coding in Objective-C, but not in Titanium.\r\n\r\nThis is important since actions taken may need to be different accordingly. E.g. When in the foreground you might just want to display a notification, but not to interrupt what users are doing. When in the background, and users click the notification to launch/resume the app, you want to take the users directly to the action.\r\n\r\nThanks.", "attachment": [], "flagged": false, "summary": "iOS: Distinguish foreground vs. background in Local Notification", "creator": { "name": "shawnlan", "key": "shawnlan", "displayName": "Shawn Lan", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "shawnlan", "key": "shawnlan", "displayName": "Shawn Lan", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "SDK 3.3.0, iOS 7", "comment": { "comments": [ { "id": "319228", "author": { "name": "ahossain", "key": "ahossain", "displayName": "Amimul Hossain", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, We have tested the issue in Ti SDK 3.3.0.GA and iOS local Notification is working when the application goes into background.\r\n\r\nh5. TESTING ENVIRONMENT\r\n\r\nCLI version 3.3.0, \r\nTitanium SDK version 3.3.0.GA\r\niOS Device, iPhone 5S, iOS Simulator\r\n\r\nh5. CODE SAMPLE\r\n\r\nh4. app.js\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor:'white'\r\n});\r\nwin.open();\r\nvar label = Ti.UI.createLabel({\r\n\ttop: 20,\r\n\theight: 200,\r\n\twidth: 200,\r\n\ttext: \"Background the app\"\r\n});\r\nwin.add(label);\r\n \r\nfunction isiOS4Plus()\r\n{\r\n\t// add iphone specific tests\r\n\tif (Titanium.Platform.name == 'iPhone OS')\r\n\t{\r\n\t\tvar version = Titanium.Platform.version.split(\".\");\r\n\t\tvar major = parseInt(version[0],10);\r\n\t\t\r\n\t\t// can only test this support on a 3.2+ device\r\n\t\tif (major >= 4)\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\treturn false;\r\n}\r\n \r\nif (isiOS4Plus())\r\n{\r\n\t// register a background service. this JS will run when the app is backgrounded but screen is OFF!!!\r\n\tvar service = Ti.App.iOS.registerBackgroundService({url:'bg.js'});\r\n \r\n\tTi.API.info(\"registered background service = \"+service);\r\n \r\n\t// listen for a local notification event\r\n\tTi.App.iOS.addEventListener('notification',function(e)\r\n\t{\r\n\t\tTi.API.info(\"local notification received: \"+JSON.stringify(e));\r\n\t});\r\n \r\n\t// fired when an app resumes for suspension\r\n\tTi.App.addEventListener('resume',function(e){\r\n\t\tTi.API.info(\"app is resuming from the background\");\r\n\t});\r\n\tTi.App.addEventListener('resumed',function(e){\r\n\t\tTi.API.info(\"app has resumed from the background\");\r\n\t});\r\n \r\n\t//This event determines that the app it was just paused\r\n\tTi.App.addEventListener('pause',function(e){\r\n\t\tTi.API.info(\"app was paused from the foreground\");\r\n\t});\r\n}\r\n{code}\r\n\r\nh4. bg.js\r\n\r\n{code}\r\n\r\n\r\nvar value = \"Hello from Running BG service - bg.js\";\r\nTi.API.info(value);\r\n \r\nvar notification = Ti.App.iOS.scheduleLocalNotification({\r\n\talertBody:\"App was put in background\",\r\n\talertAction:\"Re-Launch!\",\r\n\tuserInfo:{\"hello\":\"world\"},\r\n\tdate:new Date(new Date().getTime() + 3000) // 3 seconds after backgrounding\r\n});\r\n \r\nTi.App.iOS.addEventListener('notification',function(){\r\n\tTi.API.info('background event received = '+notification);\r\n\t//Ti.App.currentService.unregister();\r\n});\r\n \r\n{code}\r\n\r\nh5. STEP TO TEST\r\n\r\n- Create a new Classic Project\r\n- Create a new js file named \"bg.js\" in your projects resource folder.\r\n- Copy the \"app.js\" code segment to your project \"app.js\" file.\r\n- Copy the \"bg.js\" code segment to your project \"bg.js\" file.\r\n- Run the application in iPhone Device or Simulator.\r\n\r\nh5. EXPECTED RESULT\r\n\r\nWhen the application run, Put the application on background. A notification pops up after some seconds saying \"App was put in background\". Tapping on the notification will take the app into foreground.\r\n\r\nThanks.\r\n", "updateAuthor": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "created": "2014-08-19T05:44:20.000+0000", "updated": "2014-09-04T07:11:30.000+0000" }, { "id": "321865", "author": { "name": "shawnlan", "key": "shawnlan", "displayName": "Shawn Lan", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Sorry, but you misunderstand my question. First, no background service is needed. Just create any app using my example code in the index.js. Two scenarios here:\r\n\r\n1. After launching the app, press \"Home\" to put the app back to the background immediately. Now after three seconds, the notification shows, appearing in the notification center. Clicking the notification to bring back the app to the foreground, and then the \"notification\" event is fired.\r\n\r\n2. After launching the app, don't press \"Home.\" Now the app is staying in the foreground. After three seconds, the \"notification\" event is fired. No notification appear in the notification center in this case.\r\n\r\nNow, in the \"notification\" event handler, how can I distinguish the above two scenarios? The action taken can be different. For #1, it can take the user directly to the action. For #2, it may just pop up some messages.\r\n\r\nI suggest you do the same as for the push notification. It has an \"inBackground\" event property for this purpose.\r\n\r\nAt this moment, there is no way to distinguish these two scenarios for a local notification.", "updateAuthor": { "name": "shawnlan", "key": "shawnlan", "displayName": "Shawn Lan", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-09-04T17:54:26.000+0000", "updated": "2014-09-04T17:57:26.000+0000" }, { "id": "335903", "author": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "body": "Hello [~shawnlan]:\r\n\r\nCan you please provide a testcase that shows the issue? If you can provide one in Ti Classic is a lot better, so we can take Alloy out of the picture, simplyfing the problem. \r\n\r\nBest Regards", "updateAuthor": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "created": "2014-12-10T23:34:38.000+0000", "updated": "2014-12-10T23:34:38.000+0000" }, { "id": "335924", "author": { "name": "shawnlan", "key": "shawnlan", "displayName": "Shawn Lan", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This is not a bug. It doesn't matter Alloy or not. It's just some missing feature, at least I can't find it in your docs.\r\n\r\nPush Notification - you can determine if the notification received in the background or foreground.\r\n\r\nLocal Notification - \"no way\" to determine if the notification received in the background or foreground.\r\n\r\nHowever, these two types of notifications should be treated the same way, according to Apple's docs. That's why I suggest add an \"inBackground\" property to the local notification event, like you did for push notification.", "updateAuthor": { "name": "shawnlan", "key": "shawnlan", "displayName": "Shawn Lan", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-12-11T00:52:27.000+0000", "updated": "2014-12-11T00:52:27.000+0000" }, { "id": "423192", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "PR: https://github.com/appcelerator/titanium_mobile/pull/9180\r\n\r\nDemo: See the provided test-cases. There will be a new property {{inBackground}} indicating whether or not the notification was received in the background or foreground. ", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-06-29T19:19:17.000+0000", "updated": "2017-06-29T19:19:17.000+0000" }, { "id": "426508", "author": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Changes verified to be in SDK's:\r\n6.2.0.v20170810134640\r\n7.0.0.v20170808160733", "updateAuthor": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-08-10T22:36:50.000+0000", "updated": "2017-08-10T22:36:50.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }