|
@@ -19,32 +19,32 @@ static NSString* RNPDidAskForNotification = @"RNPDidAskForNotification";
|
19
|
19
|
+ (NSString *)getStatus
|
20
|
20
|
{
|
21
|
21
|
BOOL didAskForPermission = [[NSUserDefaults standardUserDefaults] boolForKey:RNPDidAskForNotification];
|
22
|
|
- BOOL isRegistered = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
|
23
|
22
|
BOOL isEnabled = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != UIUserNotificationTypeNone;
|
24
|
|
-
|
25
|
|
- if (isRegistered || isEnabled) {
|
26
|
|
- return isEnabled ? RNPStatusAuthorized : RNPStatusDenied;
|
|
23
|
+
|
|
24
|
+ if (isEnabled) {
|
|
25
|
+ return RNPStatusAuthorized;
|
27
|
26
|
} else {
|
28
|
27
|
return didAskForPermission ? RNPStatusDenied : RNPStatusUndetermined;
|
29
|
28
|
}
|
30
|
29
|
}
|
31
|
30
|
|
|
31
|
+
|
32
|
32
|
- (void)request:(UIUserNotificationType)types completionHandler:(void (^)(NSString*))completionHandler
|
33
|
33
|
{
|
34
|
34
|
NSString *status = [self.class getStatus];
|
35
|
|
-
|
|
35
|
+
|
36
|
36
|
if (status == RNPStatusUndetermined) {
|
37
|
37
|
self.completionHandler = completionHandler;
|
38
|
|
-
|
|
38
|
+
|
39
|
39
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
40
|
40
|
selector:@selector(applicationDidBecomeActive)
|
41
|
41
|
name:UIApplicationDidBecomeActiveNotification
|
42
|
42
|
object:nil];
|
43
|
|
-
|
|
43
|
+
|
44
|
44
|
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
|
45
|
45
|
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
|
46
|
46
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
47
|
|
-
|
|
47
|
+
|
48
|
48
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:RNPDidAskForNotification];
|
49
|
49
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
50
|
50
|
} else {
|
|
@@ -57,7 +57,7 @@ static NSString* RNPDidAskForNotification = @"RNPDidAskForNotification";
|
57
|
57
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
58
|
58
|
name:UIApplicationDidBecomeActiveNotification
|
59
|
59
|
object:nil];
|
60
|
|
-
|
|
60
|
+
|
61
|
61
|
if (self.completionHandler) {
|
62
|
62
|
//for some reason, checking permission right away returns denied. need to wait a tiny bit
|
63
|
63
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|