@@ -10,18 +10,22 @@ - (BOOL)application:(UIApplication *)application
1010 // MINDBOX INTEGRATION
1111 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
1212 center.delegate = self;
13- [center requestAuthorizationWithOptions: (UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge ) completionHandler: ^(BOOL granted, NSError * _Nullable error) {
14- if (!error) {
15- dispatch_async (dispatch_get_main_queue (), ^{
16- [[UIApplication sharedApplication ] registerForRemoteNotifications ];
17- [[Mindbox shared ] notificationsRequestAuthorizationWithGranted: granted];
18- });
19- }
20- else {
21- NSLog (@" NotificationsRequestAuthorization failed with error: %@ " , error.localizedDescription );
22- }
23- }];
24-
13+ if ([self shouldRegisterForRemoteNotifications ]) {
14+ [center requestAuthorizationWithOptions: (UNAuthorizationOptionSound |
15+ UNAuthorizationOptionAlert |
16+ UNAuthorizationOptionBadge ) completionHandler: ^(
17+ BOOL granted, NSError *_Nullable error) {
18+ if (!error) {
19+ dispatch_async (dispatch_get_main_queue (), ^{
20+ [[UIApplication sharedApplication ] registerForRemoteNotifications ];
21+ [[Mindbox shared ] notificationsRequestAuthorizationWithGranted: granted];
22+ });
23+ } else {
24+ NSLog (@" NotificationsRequestAuthorization failed with error: %@ " ,
25+ error.localizedDescription );
26+ }
27+ }];
28+ }
2529 // MINDBOX INTEGRATION
2630 if (@available (iOS 13.0 , *)) {
2731 [[Mindbox shared ] registerBGTasks ];
@@ -61,4 +65,8 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
6165- (void )application : (UIApplication *)application didReceiveRemoteNotification : (NSDictionary *)userInfo fetchCompletionHandler : (void (^)(UIBackgroundFetchResult))completionHandler {
6266 [[Mindbox shared ] application: application performFetchWithCompletionHandler: completionHandler];
6367}
68+
69+ - (BOOL )shouldRegisterForRemoteNotifications {
70+ return YES ;
71+ }
6472@end
0 commit comments