@@ -189,19 +189,38 @@ export let isAvailable = function () {
189
189
} ;
190
190
191
191
export let requestPermissions = function ( ) {
192
- let authStatus = PHPhotoLibrary . authorizationStatus ( ) ;
193
- if ( authStatus === PHAuthorizationStatus . NotDetermined ) {
194
- PHPhotoLibrary . requestAuthorization ( ( auth ) => {
195
- if ( auth === PHAuthorizationStatus . Authorized ) {
196
- if ( trace . isEnabled ( ) ) {
197
- trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
198
- }
199
- return ;
200
- }
201
- } ) ;
202
- } else if ( authStatus !== PHAuthorizationStatus . Authorized ) {
203
- if ( trace . isEnabled ( ) ) {
204
- trace . write ( "Application can not access photo library assets." , trace . categories . Debug ) ;
192
+ return new Promise ( function ( resolve , reject ) {
193
+ let authStatus = PHPhotoLibrary . authorizationStatus ( ) ;
194
+ switch ( authStatus ) {
195
+ case PHAuthorizationStatus . NotDetermined : {
196
+ PHPhotoLibrary . requestAuthorization ( ( auth ) => {
197
+ if ( auth === PHAuthorizationStatus . Authorized ) {
198
+ if ( trace . isEnabled ( ) ) {
199
+ trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
200
+ }
201
+ resolve ( ) ;
202
+ }
203
+ else {
204
+ reject ( ) ;
205
+ }
206
+ } ) ;
207
+ break ;
205
208
}
206
- }
209
+ case PHAuthorizationStatus . Authorized : {
210
+ if ( trace . isEnabled ( ) ) {
211
+ trace . write ( "Application can access photo library assets." , trace . categories . Debug ) ;
212
+ }
213
+ resolve ( ) ;
214
+ break ;
215
+ }
216
+ case PHAuthorizationStatus . Restricted :
217
+ case PHAuthorizationStatus . Denied : {
218
+ if ( trace . isEnabled ( ) ) {
219
+ trace . write ( "Application can not access photo library assets." , trace . categories . Debug ) ;
220
+ }
221
+ reject ( ) ;
222
+ break ;
223
+ }
224
+ }
225
+ } ) ;
207
226
} ;
0 commit comments