Browse Source

added background refresh status

Yonah Forst 9 years ago
parent
commit
9733cc6278
3 changed files with 23 additions and 2 deletions
  1. 3 1
      README.md
  2. 19 0
      ReactNativePermissions.m
  3. 1 1
      package.json

+ 3 - 1
README.md

@@ -59,9 +59,11 @@ As shown in the example, methods return a promise with the authorization status
 
 `notificationPermissionStatus()` - checks if the user has authorized remote push notifications. Note: Apple only tells us if notifications are authorized or not, not the exact status. So this promise only returns `StatusUndetermined` or `StatusAuthorized`. You can determine if `StatusUndetermined` is actually `StatusRejected` by keeping track of whether or not you've already asked the user for permission.
 
+`backgroundRefreshStatus()` - checks the authorization status of background refresh
+
 
 You also can open the Settings app.
-`openSettings()` - open the Settings app
+`openSettings()` - open the Settings app. Note: this is only supported in ios >= 8. You can use `canOpenSettings()` to determine if it's supported.
 
 ##Setup
 

+ 19 - 0
ReactNativePermissions.m

@@ -281,5 +281,24 @@ RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromis
     }
 }
 
+RCT_REMAP_METHOD(backgroundRefreshStatus, backgroundRefresh:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
+{
+    int status = [[UIApplication sharedApplication] backgroundRefreshStatus];
+    
+    switch (status) {
+        case UIBackgroundRefreshStatusAvailable:
+            return resolve(@(RNPermissionsStatusAuthorized));
+            
+        case UIBackgroundRefreshStatusDenied:
+            return resolve(@(RNPermissionsStatusDenied));
+            
+        case UIBackgroundRefreshStatusRestricted:
+            return resolve(@(RNPermissionsStatusRestricted));
+            
+        default:
+            return resolve(@(RNPermissionsStatusUndetermined));
+    }
+    
+}
 
 @end

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "react-native-permissions",
-  "version": "0.0.3",
+  "version": "0.0.4",
   "repository": {
     "type": "git",
     "url": "https://github.com/joshblour/react-native-permissions.git"