Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24018] iOS: Calling Titanium.Media.hasAudioPermissions() is crashing the app

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-12-07T05:36:01.000+0000
Affected Version/sRelease 5.5.0, Release 5.5.1
Fix Version/sRelease 6.0.1
ComponentsiOS
Labelsqe-6.0.1
ReporterShuo Liang
AssigneeHans Knöchel
Created2016-10-12T03:08:33.000+0000
Updated2016-12-19T19:32:15.000+0000

Description

Reproduce

1. Create a new default mobile app and add following code to app.js
var win = Ti.UI.createWindow({
	backgroundColor: "white"
});

var button = Ti.UI.createButton({
	title: "Test",
	top: 100,
});

button.addEventListener("click", function(){
	if (Ti.Media.hasAudioPermissions()) {
		alert('-> THIS APP HAS AUDIO PERMISSIONS');
	} else {
		alert('-> THIS APP HAS NO AUDIO PERMISSIONS');
	};
});

win.add(button);
win.open();
2. Run the app on iOS 10 device 3. Click the "Test" button

Expect Result

It should alert whether the app have Audio permission

Actual Result

App crashed and exit.

Comments

  1. Chee Kiat Ng 2016-10-12

    Sorry just realised this is audio permissions. will investigate.
  2. Hans Knöchel 2016-10-12

    The Ti.Media.hasAudioPermissions() method is only available in Titanium SDK 6.0.0 and later (see [the docs](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media-method-hasAudioPermissions)). 6.0.0 will be released in mid November, thx!
  3. Hans Knöchel 2016-12-06

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/8664 PR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8665 Test-Case: (Please set the NSMicrophoneUsageDescription key in the plist section of your tiapp.xml first)
       var win = Ti.UI.createWindow({
           backgroundColor: 'white'
       });
       
       var button = Ti.UI.createButton({
           title: 'Test audio permissions',
           top: 100,
       });
       
       button.addEventListener('click', function() {
           if (Ti.Media.hasAudioPermissions()) {
               alert('-> THIS APP HAS AUDIO PERMISSIONS');
           } else {
               Ti.API.warn('-> THIS APP HAS NO AUDIO PERMISSIONS, TRYING TO REQUEST ...');
               Ti.Media.requestAudioPermissions(function(e) {
                   if (!e.success) {
                       Ti.API.error('Requesting audio permissions failed!');
                       return;
                   }
       
                   alert('Audio permissions granted!');
               })
           };
       });
       
       win.add(button);
       win.open();
       
  4. Chee Kiat Ng 2016-12-07

    CR and FT Passed! APPROVED!
  5. sulaimaanrawoot 2016-12-15

    Hi, I have just tested this on a iphone 5s ios 9 and an iphone 6 ios 10 and it does not work. The app crashes and shuts down.
  6. Chee Kiat Ng 2016-12-15

    [~sulaimaanrawoot] did you do this (Please set the NSMicrophoneUsageDescription key in the plist section of your tiapp.xml first and read [this post](http://www.appcelerator.com/blog/2016/09/ga-release-for-titanium-sdk-5-5-0-appcelerator-cli-5-5-0-appcelerator-studio-4-7-1/) about privacy settings introduced by iOS 10).
  7. sulaimaanrawoot 2016-12-15

    Hi, yes I did. This is my plist section. UISupportedInterfaceOrientations~iphone UIInterfaceOrientationPortrait UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIRequiresPersistentWiFi UIPrerenderedIcon UIStatusBarHidden UIStatusBarStyle UIStatusBarStyleDefault NSMicrophoneUsageDescription Can we use your microphone? And this is the code: var win = Ti.UI.createWindow({ backgroundColor : 'white' }); var button = Ti.UI.createButton({ title : 'Test audio permissions', top : 100, }); button.addEventListener('click', function() { if (Ti.Media.hasAudioPermissions()) { alert('-> THIS APP HAS AUDIO PERMISSIONS'); } else { Ti.API.warn('-> THIS APP HAS NO AUDIO PERMISSIONS, TRYING TO REQUEST ...'); Ti.Media.requestAudioPermissions(function(e) { if (!e.success) { Ti.API.error('Requesting audio permissions failed!'); return; } alert('Audio permissions granted!'); }); }; }); win.add(button); win.open(); I can't see where I am going wrong. No error is logged the app just crashes. I am using sdk 6, testing on an iphone 5s running IOS 9 and I am using the latest xcode, 8.2 i think.
  8. Josh Longton 2016-12-15

    [~sulaimaanrawoot] What SDK are you using?, I have just tested on 6.0.1.v20161214184817 with Xcode 8.2 and the test case worked fine.
  9. Josh Longton 2016-12-19

    Verified fixed, using: {noformat} macOS Sierra 10.12.1 iPhone 6 (10.2) iPhone 5 (9.3.5) iOS simulator (10.2) Ti SDK 6.0.1.v20161217061750 Appc NPM 4.2.8 Appc CLI 6.1.0 Xcode 8.2 {noformat} Ti.Media.hasAudioPermissions() no longer crashes the app. *Closing ticket*

JSON Source