[TIMOB-24205] iOS: Ti.Media.CAMERA_AUTHORIZATION_* permissions are `undefined` in some 6.0.0.GA cases
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-12-19T13:19:38.000+0000 |
Affected Version/s | Release 6.0.0 |
Fix Version/s | Release 6.0.1 |
Components | iOS |
Labels | ios, media, regression |
Reporter | Tim Poulsen (ACV) |
Assignee | Hans Knöchel |
Created | 2016-12-09T19:49:18.000+0000 |
Updated | 2016-12-19T13:19:42.000+0000 |
Description
The Ti.Media.CAMERA_AUTHORIZATION_* constants are no longer defined. They all return
undefined
. Code like the following worked in our app up till 5.5.x. Updating to 6.0.0.GA it fails to recognize that the user has already granted permission.
switch (Ti.Media.cameraAuthorization) {
case Ti.Media.CAMERA_AUTHORIZATION_AUTHORIZED:
// camera permissions granted, do something like
Ti.Media.showCamera();
break;
case Ti.Media.CAMERA_AUTHORIZATION_DENIED:
case Ti.Media.CAMERA_AUTHORIZATION_RESTRICTED:
// they have denied access to the camera
alert('You denied camera permission. Use Settings to grant them');
break;
default:
// they'll be prompted for perms...
}
console.log(Ti.Media.cameraAuthorization); // => 3
console.log(Ti.Media.CAMERA_AUTHORIZATION_AUTHORIZED); // => undefined
console.log(Ti.Media.CAMERA_AUTHORIZATION_DENIED); // => undefined
TIMOB-17812 shows a similar way to use these constants. Our app has been using them since iOS8 was first released. They are still documented in the Ti.Media pages. I see nothing in the 6.x release notes about them being removed.
The following code works, but is not equivalent. For example, it won't let me differentiate between a user who has not yet granted permissions and one who has explicitly denied permissions. That means I can't show them a custom app dialog to tell them what great features they're missing by having denied permissions.
if (OS_IOS) {
if (Ti.Media.hasCameraPermissions()) {
// yay!
} else {
// boo hoo
}
}
My quote from Slack: {quote} Camera constants are only compiled for device builds when you use the camera API's. The background is the pre-6.0.0 issue where Apple rejected apps because of camera API's although you didn't use them. In 6.0.0, we checked those more smart so the symbols are only generated when you use the related camera api's. Currently, it gets generated when you use
Ti.Media.hasCameraPermissions()
orTi.Media.hasAudioPermissions()
, so it should probably be improved. {quote} The fix is quite easy, i would add theTI_MEDIACAMERAAUTHORIZATION
for the valid symbol that trigger the API compilation. Are there other (independent) API's / use.cases where you would use the constants in combination with? Thx!PR (master): https://github.com/appcelerator/titanium_mobile/pull/8674 PR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8675
Thanks for the fast response Hans. Obviously, I haven't tested your solution but the explanation makes sense and your PR looks like it should resolve the issue. It looks like you've made the change for just camera but not audio related constants. Should you do both?
Which ones do you mean again?
AUDIO_SESSION_PORT_\*
,AUDIO_SESSION_OVERRIDE_ROUTE_\*
andAUDIO_SESSION_CATEGORY_\*
are available when you use one of this API's: - Ti.Media.AudioPlayer - Ti.Media.MusicPlayer - Ti.Media.VideoPlayer - Ti.Media.Sound - Ti.Media.AudioRecorderSorry, I was comparing your statement above that both audio and camera properties would be defined if you used related APIs with the fact that your PR made changes to camera properties only. Therefore, I was assuming that maybe similar changes would have been needed for audio properties. I see that's not the case. So, disregard my audio-related comment.
NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.1.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.0.1.v20161215113432 Appcelerator Studio, build: 4.8.1.201612050850 Xcode 8.1 and 8.2 iOS Devices: 9.3 and 10.1.1 Validated fix with the above environment. I installed an app with the code above, and found that "defined" is not returned to console.