Skip to content

Commit

Permalink
Return error callback when the user chooses 'Don't allow' when regist…
Browse files Browse the repository at this point in the history
…ering for push notifications in iOS
  • Loading branch information
mkapostolov committed Jun 1, 2017
1 parent 9853a69 commit d6f855d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ios/AppDelegate+notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "AppDelegate.h"

@interface AppDelegate (notification)
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
Expand Down
5 changes: 5 additions & 0 deletions src/ios/AppDelegate+notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ - (void)onApplicationDidBecomeActive:(NSNotification *)notification
}
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"];
[pushHandler didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"];
[pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
Expand Down
1 change: 1 addition & 0 deletions src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

- (void)register:(CDVInvokedUrlCommand*)command;
- (void)registerUserNotificationSettings:(CDVInvokedUrlCommand*)command;
- (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;

- (void)areNotificationsEnabled:(CDVInvokedUrlCommand*)command;

Expand Down
9 changes: 9 additions & 0 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ - (void)isEnabled:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)op
NSLog(@"JSStatement %@",jsStatement);
}
*/

- (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
// Check if the user has chosen not to recieve notifications for this app
if(notificationSettings.types == UIUserNotificationTypeNone)
{
[self failWithMessage:@"User did not allow notification messages for this app" withError:nil];
}
}

- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

Expand Down

0 comments on commit d6f855d

Please sign in to comment.