Browse Source

better notification handling. bump

Yonah Forst 8 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 View File

@@ -57,7 +57,7 @@ As shown in the example, methods return a promise with the authorization status
57 57
 
58 58
 `bluetoothPermissionStatus()` - checks the authorization status of the `CBPeripheralManager` (for sharing data while backgrounded). Note: _Don't_ use this if you're only using `CBCentralManager`
59 59
 
60
-`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.
60
+`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...
61 61
 
62 62
 `backgroundRefreshStatus()` - checks the authorization status of background refresh
63 63
 

+ 5
- 4
ReactNativePermissions.m View File

@@ -255,13 +255,15 @@ RCT_REMAP_METHOD(bluetoothPermissionStatus, bluetoothPermission:(RCTPromiseResol
255 255
     
256 256
 }
257 257
 
258
-//problem here is that we can only return Authorized or Undetermined
258
+//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
259 259
 RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
260 260
 {
261 261
     if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
262 262
         // iOS8+
263
-        if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
264
-            return resolve(@(RNPermissionsStatusAuthorized));
263
+        BOOL isRegistered = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
264
+        BOOL isEnabled = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != UIUserNotificationTypeNone;
265
+        if (isRegistered || isEnabled) {
266
+            return resolve(@(isEnabled ? RNPermissionsStatusAuthorized : RNPermissionsStatusDenied));
265 267
         }
266 268
         else {
267 269
             return resolve(@(RNPermissionsStatusUndetermined));
@@ -277,7 +279,6 @@ RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromis
277 279
         #else
278 280
             return resolve(@(RNPermissionsStatusUndetermined));
279 281
         #endif
280
-
281 282
     }
282 283
 }
283 284
 

+ 1
- 1
package.json View File

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