Browse Source

better notification handling. bump

Yonah Forst 9 years ago
parent
commit
443f63e36d
3 changed files with 7 additions and 6 deletions
  1. 1 1
      README.md
  2. 5 4
      ReactNativePermissions.m
  3. 1 1
      package.json

+ 1 - 1
README.md

@@ -57,7 +57,7 @@ As shown in the example, methods return a promise with the authorization status
 
 `bluetoothPermissionStatus()` - checks the authorization status of the `CBPeripheralManager` (for sharing data while backgrounded). Note: _Don't_ use this if you're only using `CBCentralManager`
 
-`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.
+`notificationPermissionStatus()` - checks if the user has authorized remote push notifications. Note: iOS only tells us if the user has ever registered for notification, and which notifications are enabled. Therefore we cannot tell the difference between a user who has never been prompted for notification and a user who denied permission; both will return `StatusUndetermined`. You can determine if `StatusUndetermined` is actually `StatusDenied` by keeping track of whether or not you've already asked the user for permission. This promise *can* return `StatusDenied` if the user switched notifications off from the settings menu. Confusing, I know...
 
 `backgroundRefreshStatus()` - checks the authorization status of background refresh
 

+ 5 - 4
ReactNativePermissions.m

@@ -255,13 +255,15 @@ RCT_REMAP_METHOD(bluetoothPermissionStatus, bluetoothPermission:(RCTPromiseResol
     
 }
 
-//problem here is that we can only return Authorized or Undetermined
+//problem here is that we can we can't know if the user was never prompted for permission, or if they were prompted and deneied
 RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
 {
     if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
         // iOS8+
-        if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
-            return resolve(@(RNPermissionsStatusAuthorized));
+        BOOL isRegistered = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
+        BOOL isEnabled = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != UIUserNotificationTypeNone;
+        if (isRegistered || isEnabled) {
+            return resolve(@(isEnabled ? RNPermissionsStatusAuthorized : RNPermissionsStatusDenied));
         }
         else {
             return resolve(@(RNPermissionsStatusUndetermined));
@@ -277,7 +279,6 @@ RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromis
         #else
             return resolve(@(RNPermissionsStatusUndetermined));
         #endif
-
     }
 }
 

+ 1 - 1
package.json

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