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