|  | @@ -23,15 +23,17 @@
 | 
	
		
			
			| 23 | 23 |  #import <AVFoundation/AVFoundation.h>
 | 
	
		
			
			| 24 | 24 |  #import <CoreBluetooth/CoreBluetooth.h>
 | 
	
		
			
			| 25 | 25 |  
 | 
	
		
			
			|  | 26 | +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
 | 
	
		
			
			|  | 27 | +@import Contacts;
 | 
	
		
			
			|  | 28 | +@import Photos;
 | 
	
		
			
			|  | 29 | +#endif
 | 
	
		
			
			|  | 30 | +
 | 
	
		
			
			|  | 31 | +
 | 
	
		
			
			| 26 | 32 |  @interface ReactNativePermissions()
 | 
	
		
			
			| 27 | 33 |  @end
 | 
	
		
			
			| 28 | 34 |  
 | 
	
		
			
			| 29 | 35 |  @implementation ReactNativePermissions
 | 
	
		
			
			| 30 | 36 |  
 | 
	
		
			
			| 31 |  | -+ (BOOL)useContactsFramework
 | 
	
		
			
			| 32 |  | -{
 | 
	
		
			
			| 33 |  | -    return [[CNContactStore alloc] init] != nil;
 | 
	
		
			
			| 34 |  | -}
 | 
	
		
			
			| 35 | 37 |  
 | 
	
		
			
			| 36 | 38 |  RCT_EXPORT_MODULE();
 | 
	
		
			
			| 37 | 39 |  @synthesize bridge = _bridge;
 | 
	
	
		
			
			|  | @@ -54,10 +56,19 @@ RCT_EXPORT_MODULE();
 | 
	
		
			
			| 54 | 56 |                @"StatusRestricted" : @(RNPermissionsStatusRestricted)};
 | 
	
		
			
			| 55 | 57 |  };
 | 
	
		
			
			| 56 | 58 |  
 | 
	
		
			
			|  | 59 | +
 | 
	
		
			
			|  | 60 | +- (BOOL)canOpenSettings {
 | 
	
		
			
			|  | 61 | +    return UIApplicationOpenSettingsURLString != nil;
 | 
	
		
			
			|  | 62 | +}
 | 
	
		
			
			|  | 63 | +
 | 
	
		
			
			|  | 64 | +RCT_REMAP_METHOD(canOpenSettings, canOpenSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
 | 
	
		
			
			|  | 65 | +{
 | 
	
		
			
			|  | 66 | +    resolve(@([self canOpenSettings]));
 | 
	
		
			
			|  | 67 | +}
 | 
	
		
			
			|  | 68 | +
 | 
	
		
			
			| 57 | 69 |  RCT_EXPORT_METHOD(openSettings)
 | 
	
		
			
			| 58 | 70 |  {
 | 
	
		
			
			| 59 |  | -    BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
 | 
	
		
			
			| 60 |  | -    if (canOpenSettings) {
 | 
	
		
			
			|  | 71 | +    if ([self canOpenSettings]) {
 | 
	
		
			
			| 61 | 72 |          NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
 | 
	
		
			
			| 62 | 73 |          [[UIApplication sharedApplication] openURL:url];
 | 
	
		
			
			| 63 | 74 |      }
 | 
	
	
		
			
			|  | @@ -125,26 +136,43 @@ RCT_REMAP_METHOD(microphonePermissionStatus, microphonePermission:(RCTPromiseRes
 | 
	
		
			
			| 125 | 136 |  RCT_REMAP_METHOD(photoPermissionStatus, photoPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
 | 
	
		
			
			| 126 | 137 |  
 | 
	
		
			
			| 127 | 138 |  {
 | 
	
		
			
			| 128 |  | -    int status = [ALAssetsLibrary authorizationStatus];
 | 
	
		
			
			| 129 |  | -    switch (status) {
 | 
	
		
			
			| 130 |  | -        case ALAuthorizationStatusAuthorized:
 | 
	
		
			
			| 131 |  | -            return resolve(@(RNPermissionsStatusAuthorized));
 | 
	
		
			
			| 132 |  | -            
 | 
	
		
			
			| 133 |  | -        case ALAuthorizationStatusDenied:
 | 
	
		
			
			| 134 |  | -            return resolve(@(RNPermissionsStatusDenied));
 | 
	
		
			
			| 135 |  | -            
 | 
	
		
			
			| 136 |  | -        case ALAuthorizationStatusRestricted:
 | 
	
		
			
			| 137 |  | -            return resolve(@(RNPermissionsStatusRestricted));
 | 
	
		
			
			| 138 |  | -            
 | 
	
		
			
			| 139 |  | -        default:
 | 
	
		
			
			| 140 |  | -            return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			| 141 |  | -    }
 | 
	
		
			
			|  | 139 | +    #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
 | 
	
		
			
			|  | 140 | +        int status = [PHPhotoLibrary authorizationStatus];
 | 
	
		
			
			|  | 141 | +        switch (status) {
 | 
	
		
			
			|  | 142 | +            case PHAuthorizationStatusAuthorized:
 | 
	
		
			
			|  | 143 | +                return resolve(@(RNPermissionsStatusAuthorized));
 | 
	
		
			
			|  | 144 | +                
 | 
	
		
			
			|  | 145 | +            case PHAuthorizationStatusDenied:
 | 
	
		
			
			|  | 146 | +                return resolve(@(RNPermissionsStatusDenied));
 | 
	
		
			
			|  | 147 | +                
 | 
	
		
			
			|  | 148 | +            case PHAuthorizationStatusRestricted:
 | 
	
		
			
			|  | 149 | +                return resolve(@(RNPermissionsStatusRestricted));
 | 
	
		
			
			|  | 150 | +                
 | 
	
		
			
			|  | 151 | +            default:
 | 
	
		
			
			|  | 152 | +                return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			|  | 153 | +        }
 | 
	
		
			
			|  | 154 | +    #else
 | 
	
		
			
			|  | 155 | +        int status = ABAddressBookGetAuthorizationStatus();
 | 
	
		
			
			|  | 156 | +        switch (status) {
 | 
	
		
			
			|  | 157 | +            case kABAuthorizationStatusAuthorized:
 | 
	
		
			
			|  | 158 | +                return resolve(@(RNPermissionsStatusAuthorized));
 | 
	
		
			
			|  | 159 | +                
 | 
	
		
			
			|  | 160 | +            case kABAuthorizationStatusDenied:
 | 
	
		
			
			|  | 161 | +                return resolve(@(RNPermissionsStatusDenied));
 | 
	
		
			
			|  | 162 | +                
 | 
	
		
			
			|  | 163 | +            case kABAuthorizationStatusRestricted:
 | 
	
		
			
			|  | 164 | +                return resolve(@(RNPermissionsStatusRestricted));
 | 
	
		
			
			|  | 165 | +                
 | 
	
		
			
			|  | 166 | +            default:
 | 
	
		
			
			|  | 167 | +                return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			|  | 168 | +        }
 | 
	
		
			
			|  | 169 | +    #endif
 | 
	
		
			
			|  | 170 | +
 | 
	
		
			
			| 142 | 171 |  }
 | 
	
		
			
			| 143 | 172 |  
 | 
	
		
			
			| 144 | 173 |  RCT_REMAP_METHOD(contactsPermissionStatus, contactsPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
 | 
	
		
			
			| 145 | 174 |  {
 | 
	
		
			
			| 146 |  | -    if ([ReactNativePermissions useContactsFramework])
 | 
	
		
			
			| 147 |  | -    {
 | 
	
		
			
			|  | 175 | +    #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
 | 
	
		
			
			| 148 | 176 |          int status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
 | 
	
		
			
			| 149 | 177 |          switch (status) {
 | 
	
		
			
			| 150 | 178 |              case CNAuthorizationStatusAuthorized:
 | 
	
	
		
			
			|  | @@ -159,8 +187,7 @@ RCT_REMAP_METHOD(contactsPermissionStatus, contactsPermission:(RCTPromiseResolve
 | 
	
		
			
			| 159 | 187 |              default:
 | 
	
		
			
			| 160 | 188 |                  return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			| 161 | 189 |          }
 | 
	
		
			
			| 162 |  | -    }
 | 
	
		
			
			| 163 |  | -    else {
 | 
	
		
			
			|  | 190 | +    #else
 | 
	
		
			
			| 164 | 191 |          int status = ABAddressBookGetAuthorizationStatus();
 | 
	
		
			
			| 165 | 192 |          switch (status) {
 | 
	
		
			
			| 166 | 193 |              case kABAuthorizationStatusAuthorized:
 | 
	
	
		
			
			|  | @@ -175,7 +202,7 @@ RCT_REMAP_METHOD(contactsPermissionStatus, contactsPermission:(RCTPromiseResolve
 | 
	
		
			
			| 175 | 202 |              default:
 | 
	
		
			
			| 176 | 203 |                  return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			| 177 | 204 |          }
 | 
	
		
			
			| 178 |  | -    }
 | 
	
		
			
			|  | 205 | +    #endif
 | 
	
		
			
			| 179 | 206 |  }
 | 
	
		
			
			| 180 | 207 |  
 | 
	
		
			
			| 181 | 208 |  
 | 
	
	
		
			
			|  | @@ -240,14 +267,18 @@ RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromis
 | 
	
		
			
			| 240 | 267 |              return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			| 241 | 268 |          }
 | 
	
		
			
			| 242 | 269 |      } else {
 | 
	
		
			
			| 243 |  | -        if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
 | 
	
		
			
			|  | 270 | +        #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
 | 
	
		
			
			|  | 271 | +            if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
 | 
	
		
			
			|  | 272 | +                return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			|  | 273 | +            }
 | 
	
		
			
			|  | 274 | +            else {
 | 
	
		
			
			|  | 275 | +                return resolve(@(RNPermissionsStatusAuthorized));
 | 
	
		
			
			|  | 276 | +            }
 | 
	
		
			
			|  | 277 | +        #else
 | 
	
		
			
			| 244 | 278 |              return resolve(@(RNPermissionsStatusUndetermined));
 | 
	
		
			
			| 245 |  | -        }
 | 
	
		
			
			| 246 |  | -        else {
 | 
	
		
			
			| 247 |  | -            return resolve(@(RNPermissionsStatusAuthorized));
 | 
	
		
			
			| 248 |  | -        }
 | 
	
		
			
			| 249 |  | -    }
 | 
	
		
			
			|  | 279 | +        #endif
 | 
	
		
			
			| 250 | 280 |  
 | 
	
		
			
			|  | 281 | +    }
 | 
	
		
			
			| 251 | 282 |  }
 | 
	
		
			
			| 252 | 283 |  
 | 
	
		
			
			| 253 | 284 |  
 |