@@ -176,38 +176,76 @@ export let isAvailable = function () {
176176} ;
177177
178178export let requestPermissions = function ( ) {
179- return new Promise ( function ( resolve , reject ) {
180- let authStatus = PHPhotoLibrary . authorizationStatus ( ) ;
181- switch ( authStatus ) {
182- case PHAuthorizationStatus . NotDetermined : {
183- PHPhotoLibrary . requestAuthorization ( ( auth ) => {
184- if ( auth === PHAuthorizationStatus . Authorized ) {
185- if ( trace . isEnabled ( ) ) {
186- trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
187- }
188- resolve ( ) ;
189- }
190- else {
179+ return new Promise ( function ( resolve , reject ) {
180+ requestPhotosPermissions ( ) . then ( ( ) => {
181+ requestCameraPermissions ( ) . then ( resolve , reject ) ;
182+ } , reject ) ;
183+ } ) ;
184+ } ;
185+
186+ let requestPhotosPermissions = function ( ) {
187+ return new Promise ( function ( resolve , reject ) {
188+ let authStatus = PHPhotoLibrary . authorizationStatus ( ) ;
189+ switch ( authStatus ) {
190+ case PHAuthorizationStatus . NotDetermined : {
191+ PHPhotoLibrary . requestAuthorization ( ( auth ) => {
192+ if ( auth === PHAuthorizationStatus . Authorized ) {
193+ if ( trace . isEnabled ( ) ) {
194+ trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
195+ }
196+ resolve ( ) ;
197+ }
198+ else {
199+ reject ( ) ;
200+ }
201+ } ) ;
202+ break ;
203+ }
204+ case PHAuthorizationStatus . Authorized : {
205+ if ( trace . isEnabled ( ) ) {
206+ trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
207+ }
208+ resolve ( ) ;
209+ break ;
210+ }
211+ case PHAuthorizationStatus . Restricted :
212+ case PHAuthorizationStatus . Denied : {
213+ if ( trace . isEnabled ( ) ) {
214+ trace . write ( "Application can not access photo library assets." , trace . categories . Debug ) ;
215+ }
191216 reject ( ) ;
192- }
193- } ) ;
194- break ;
195- }
196- case PHAuthorizationStatus . Authorized : {
197- if ( trace . isEnabled ( ) ) {
198- trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
199- }
200- resolve ( ) ;
201- break ;
217+ break ;
218+ }
202219 }
203- case PHAuthorizationStatus . Restricted :
204- case PHAuthorizationStatus . Denied : {
205- if ( trace . isEnabled ( ) ) {
206- trace . write ( "Application can not access photo library assets." , trace . categories . Debug ) ;
207- }
208- reject ( ) ;
209- break ;
220+ } ) ;
221+ } ;
222+
223+ let requestCameraPermissions = function ( ) {
224+ return new Promise ( function ( resolve , reject ) {
225+ let cameraStatus = AVCaptureDevice . authorizationStatusForMediaType ( AVMediaTypeVideo ) ;
226+ switch ( cameraStatus ) {
227+ case AVAuthorizationStatus . NotDetermined : {
228+ AVCaptureDevice . requestAccessForMediaTypeCompletionHandler ( AVMediaTypeVideo , ( granted ) => {
229+ if ( granted ) {
230+ resolve ( ) ;
231+ } else {
232+ reject ( ) ;
233+ }
234+ } ) ;
235+ break ;
236+ }
237+ case AVAuthorizationStatus . Authorized : {
238+ resolve ( ) ;
239+ break ;
240+ }
241+ case AVAuthorizationStatus . Restricted :
242+ case AVAuthorizationStatus . Denied : {
243+ if ( trace . isEnabled ( ) ) {
244+ trace . write ( "Application can not access Camera assets." , trace . categories . Debug ) ;
245+ }
246+ reject ( ) ;
247+ break ;
248+ }
210249 }
211- }
212250 } ) ;
213251} ;
0 commit comments