{ "id": "166568", "key": "TIMOB-24476", "fields": { "issuetype": { "id": "7", "description": "gh.issue.story.desc", "name": "Story", "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": [], "resolution": { "id": "11", "description": "Is not a bug in our product", "name": "Not Our Bug" }, "resolutiondate": "2017-03-25T15:49:43.000+0000", "created": "2017-03-11T17:03:19.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2017-05-31T22:24:56.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": "h6.description\r\nIs it possible to activate the audio recorder when exiting the App? (pressed the home button for exiting the app)\r\n\r\nI have tried with the following test code but it's not working.\r\n\r\n{code:title=app.js}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor : 'green',\r\n\tlayout : \"vertical\"\r\n\r\n});\r\n\r\nwin.open();\r\n\r\nfunction onResume() {\r\n\r\n\trecorder.stop();\r\n\r\n\tTi.Media.audioSessionCategory = Ti.Media.AUDIO_SESSION_CATEGORY_PLAYBACK;\r\n\tTi.API.info(\"onReasume\");\r\n\r\n}\r\n\r\nfunction onPause() {\r\n\r\n\tTi.Media.audioSessionCategory = Ti.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD;\r\n\r\n\trecorder.start();\r\n\tTi.API.info(\"onPause\");\r\n\r\n}\r\n\r\nvar recorder = Ti.Media.createAudioRecorder();\r\n\r\nTi.App.addEventListener(\"resumed\", onResume);\r\n\r\nTi.App.addEventListener(\"pause\", onPause);\r\n\r\n\r\n{code}\r\n\r\nIf I press the home button then reopen it, several times, it shows this error.\r\n\r\n{code:title=console log}\r\n[ERROR] : Script Error {\r\n[ERROR] : column = 15;\r\n[ERROR] : line = 63;\r\n[ERROR] : message = \"+[NSBlock boundBridge:withKrollObject:]: unrecognized selector sent to class 0x1a91ccd58\";\r\n[ERROR] : sourceURL = \"file:///var/containers/Bundle/Application/03E1B455-31D7-4FB0-8509-CF99D1F972D8/commonJSApp.app/app.js\";\r\n[ERROR] : stack = \"[native code]\\nonResume@file:///var/containers/Bundle/Application/03E1B455-31D7-4FB0-8509-CF99D1F972D8/commonJSApp.app/app.js:63:15\";\r\n[ERROR] : }\r\n\r\n{code}\r\n\r\nThanks.", "attachment": [ { "id": "61835", "filename": "test_media.zip", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-12T18:02:49.000+0000", "size": 2545123, "mimeType": "application/zip" } ], "flagged": false, "summary": "iOS: Audio recording when exiting the app.", "creator": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "subtasks": [], "reporter": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "environment": "Titanium SDK\r\n SDK Version = 6.0.2.GA\r\n Target Platform = iphone 5s v10.2.1\r\nOperating System\r\n Name = Mac OS X\r\n Version = 10.12.3\r\n Architecture = 64bit\r\n # CPUs = 4\r\n Memory = 8589934592\r\nNode.js\r\n Node.js Version = 4.6.2\r\n npm Version = 2.15.11\r\nTitanium CLI\r\n CLI Version = 5.0.11\r\n", "closedSprints": [ { "id": 854, "state": "closed", "name": "2017 Sprint 06 SDK", "startDate": "2017-03-12T19:14:58.337Z", "endDate": "2017-03-26T19:14:00.000Z", "completeDate": "2017-03-26T22:01:15.828Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "411387", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "The error indicates a problem in line 64, but the test-case only has 31 lines. Please check!\r\n\r\n*EDIT*: I am able to reproduce this issue. Putting it in the current sprint and 6.0.3 release version for now. If possible, it would be very helpful to know if this used to work with 5.5.1.GA.\r\n\r\n*EDIT 2*: The error did not happen to me when using the latest 6.0.3 build together with the following tiapp.xml properties:\r\n{code:xml}\r\nNSMicrophoneUsageDescription\r\nCan we use your microphone?\r\nUIBackgroundModes\r\n\r\n audio\r\n\r\n{code}\r\n\r\nI also attached my example project that's based on your code. It works fine now and the red status bar appears to indicate the background recording to the user (that's native).", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-12T16:17:20.000+0000", "updated": "2017-03-12T18:00:18.000+0000" }, { "id": "411401", "author": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hans can you run it multiple times... sometimes it works and sometimes it doesn't. Run it 5 times (rebuild every time and exit the app from the task manager) on/off liveview (important that you try both) if you never get a \"Could not activate session\" message then it's solved. otherwise please inform me", "updateAuthor": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-03-13T11:04:04.000+0000", "updated": "2017-03-13T11:05:50.000+0000" }, { "id": "411403", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Then it's solved :-) I received the message before, but after doing the above changes, it works now. You did test the changes and checked my example project right? And you can get the latest 6.0.3 build from [here|http://builds.appcelerator.com/#6_0_X] (release this / next week).", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-13T11:14:12.000+0000", "updated": "2017-03-13T11:15:40.000+0000" }, { "id": "412477", "author": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "body": "hans I checked it again with sdk version 6.0.3.v20170314141715 and I am still getting\r\n [INFO] : Could not activate session\r\nwhen trying to activate the audio recorder when exiting the app\r\ncan you please look into that?", "updateAuthor": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-03-15T09:41:25.000+0000", "updated": "2017-03-15T09:41:25.000+0000" }, { "id": "412482", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "You ensured to included the above keys into your ios section of the tiapp.xml? Then I'd like to request the tiapp.xml to clarify.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-15T11:34:32.000+0000", "updated": "2017-03-15T11:34:32.000+0000" }, { "id": "412492", "author": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "body": "yes! of course I included them. you may not get the bug because this behavior is incosistent (most times it works sometimes it doesn't)\r\n\r\nhere is the tiapp.xml so you \r\n\r\n{code:xml}\r\n\r\n\r\n com.tamir.wakeapp\r\n wakeapp\r\n 1.0\r\n tamir\r\n undefined\r\n undefined\r\n 2016 by tamir\r\n appicon.png\r\n false\r\n false\r\n true\r\n 996fbe63-xxxx-xxxx-xxxx-49ba79a8eee9\r\n dp\r\n \r\n true\r\n \r\n \r\n NSLocationAlwaysUsageDescription\r\n we need to keep track of your location to wake you up when you arrive at your destination\r\n NSMicrophoneUsageDescription\r\n because\r\n NSAppleMusicUsageDescription\r\n enable if you wish to use songs from your music library\r\n UISupportedInterfaceOrientations\r\n \r\n UIInterfaceOrientationPortrait\r\n \r\n UIBackgroundModes\r\n \r\n audio\r\n \r\n UIRequiresPersistentWiFi\r\n \r\n UIPrerenderedIcon\r\n \r\n UIStatusBarHidden\r\n \r\n UIStatusBarStyle\r\n UIStatusBarStyleDefault\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n true\r\n true\r\n \r\n default\r\n \r\n \r\n ti.cloud\r\n \r\n \r\n false\r\n false\r\n true\r\n false\r\n false\r\n \r\n 6.0.3.v20170314141715\r\n \r\n ti.alloy\r\n \r\n\r\n\r\n{code}\r\n\r\nWhen I said try multiple times I meant it.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-15T15:21:29.000+0000", "updated": "2017-03-24T21:34:07.000+0000" }, { "id": "413485", "author": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "body": "have you experienced the bug yet?", "updateAuthor": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-03-17T14:28:10.000+0000", "updated": "2017-03-17T14:28:10.000+0000" }, { "id": "415748", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Any updates on it?", "updateAuthor": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2017-03-24T20:45:02.000+0000", "updated": "2017-03-24T20:45:02.000+0000" }, { "id": "415793", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hey Tamir,\r\n\r\nI am still not getting the error any more when using the background-modes like in the example project. I also cleaned up the event-handling of the app.js to only register the events when the audio permissions are granted properly. Try this please:\r\n{code:js}\r\nvar recorder = null;\r\n\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor : 'green',\r\n\tlayout : \"vertical\"\r\n});\r\n\r\nwin.addEventListener(\"open\", function() {\r\n\tif (!Ti.Media.hasAudioPermissions()) {\r\n\t\tTi.Media.requestAudioPermissions(function(e) {\r\n\t\t\tif (!e.success) {\r\n\t\t\t\talert(\"Audio Recording Permissions not granted. Skipping!\");\r\n\t\t\t\treturn;\r\n\t\t\t}\t\t\r\n\t\t\t\r\n\t\t\tTi.API.info('Audio Recorder Permissions now granted!');\r\n\t\t\tinitializeAudioEvents();\r\n\t\t});\r\n\t} else {\r\n\t\tTi.API.info('Audio Recorder Permissions already granted!');\r\n\t\tinitializeAudioEvents();\r\n\t}\r\n});\r\n \r\nwin.open();\r\n\r\nfunction initializeAudioEvents() {\r\n\trecorder = Ti.Media.createAudioRecorder();\r\n\r\n\tTi.App.addEventListener(\"resumed\", onResume);\r\n\tTi.App.addEventListener(\"pause\", onPause);\r\n}\r\n \r\nfunction onResume() {\r\n\tif (!recorder) {\r\n\t\treturn;\r\n\t}\r\n \r\n\trecorder.stop();\r\n \r\n\tTi.Media.audioSessionCategory = Ti.Media.AUDIO_SESSION_CATEGORY_PLAYBACK;\r\n\t\r\n\tTi.API.warn(\"category: \" + Ti.Media.audioSessionCategory);\r\n\tTi.API.warn(\"playback: \" + Ti.Media.AUDIO_SESSION_CATEGORY_PLAYBACK);\r\n\t\r\n\tTi.API.info(\"onResume\");\r\n \r\n}\r\n \r\nfunction onPause() {\r\n\tif (!recorder) {\r\n\t\treturn;\r\n\t}\r\n \r\n\tTi.Media.audioSessionCategory = Ti.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD;\r\n \r\n\tTi.API.warn(\"category: \" + Ti.Media.audioSessionCategory);\r\n Ti.API.warn(\"play_and_record: \" + Ti.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD);\r\n \r\n\trecorder.start();\r\n\tTi.API.info(\"onPause\");\r\n}\r\n{code}\r\n\r\nAnd for better debugging, please go to {{~/Library/Application Support/Titanium/mobilesdk/osx/6.0.3.GA/iphone/Classes/TiMediaAudioSession.m}} and change the line 45 to {{DebugLog(@\"Could not activate session: %@ (%ld)\", error.localizedDescription, error.code);}}, so we can see what's the actual error and code. Thx!\r\n\r\nP.S.: Also note that you have to know that when you force-quit the app and open it again, it will of course create a new recorder instance to record, so you should really be careful with adding the global events. I am not sure how this is natively done, but you could probably store the current audio session ID and check if that one is currently running before creating a new recorder. I hope that's clear to understand.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-24T21:33:39.000+0000", "updated": "2017-03-24T21:42:37.000+0000" }, { "id": "415820", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "I was just able to reproduce the error and received the internal error code {{561015905}}, which means that the audio session could not be activated from the background. Digging more into it, it looks like you cannot start audio sessions from the background (especially not when the app gets closed). See [this|https://forums.developer.apple.com/thread/38917] and [this|https://developer.apple.com/reference/avfoundation/avaudiosessionerrorcode/avaudiosessionerrorcodecannotstartplaying] link for more technical details from Apple directly. So I have to correct myself: You can record when the app is paused (not terminated), but only when you start the recording in the foreground already. The background modes are for that state, but also primarily for *playing* audio, which also works when the app is terminated. I hope that helps a bit. Please feel free to get in touch with Apple for more detailed API behaviors, thanks!", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-24T22:04:20.000+0000", "updated": "2017-03-24T22:04:20.000+0000" }, { "id": "415829", "author": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "body": "thanks Hans, good to know that.\r\n\r\nI have question that isn't entirely on subject. Do you have any idea about the kind of background mode sleep cycle is using?\r\n(it's not audio recording I checked by disabling the microphone for the app and this still works. plus when I use the microphone in the background the lock screen looks differently than what it looks like when sleep cycle is in the background.)\r\nIf not, do you have any idea about who can I talk to about that?\r\n\r\nthanks in advance, Tamir.", "updateAuthor": { "name": "tamirishaysh", "key": "tamirishaysh", "displayName": "Tamir Ishay Sharbat", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-03-25T15:45:35.000+0000", "updated": "2017-03-25T15:45:35.000+0000" }, { "id": "415830", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hey Tamir, that's a very general iOS question. I'd ask a new question on StackOverflow, there are audio-related experts that will be able to give you a solid answer on that, I'd need to do some more research to do the same. Thanks man!", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-03-25T15:49:28.000+0000", "updated": "2017-03-25T15:49:28.000+0000" }, { "id": "420720", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing this issue as the problem is not our bug.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-05-31T22:24:56.000+0000", "updated": "2017-05-31T22:24:56.000+0000" } ], "maxResults": 13, "total": 13, "startAt": 0 } } }