iOS Question Safeway for all IOS version to check Remote Notifications iOS 9 trough iOS 11

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the equivalent B4i code:
B4X:
Dim no As NativeObject
no = no.Initialize("UIApplication").RunMethod("sharedApplication", Null).RunMethod("currentUserNotificationSettings", Null)
Dim types As Int = no.GetField("types").AsNumber
If types = 0 Then
   Log("No notifications allowed")
Else
   Log("Notifications are enabled")
End If
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
Thans @Erel but the solution you mention I have already looked for it. We need to go a little further.

For example, an app that only request notifications when an user action is held in the app then the app queries:

Is the first time the user request notifications?
We tell the user that we need notifications (MSGBOX) with Continue or Cancel. If it chooses continue, then we request the notifications from the App and the user is presented with the Allow/Don't Allow dialogue.

If the user chooses Don't Allow, I cancel the request. When he chooses again the request, then I cannot present the user with the RegisterForRemoteNotifications because he already denied it, so I have to take him to the app settings so he can allow manually (prev MSGBOX warning the user)

This last point is where the old code does not work. I have tried with another piece ob OBJC with no luch, as it is not a direct return method. This snippet returns Authorized, not Authorized or Denied, which would be perfect whith my request. But I cannot figure out how to return the value within this OBJC when OSVersion>8 under the CompletionHandler


B4X:
#import <UserNotifications/UserNotifications.h>

- (VOID)checkPerms{
   if #available(iOS 9, *) {
       UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
       [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
       switch (settings.authorizationStatus) {
       case UNAuthorizationStatusAuthorized:
           NSLog(@"Status Authorized");
           break;
       case UNAuthorizationStatusDenied:
           NSLog(@"Status Denied");
           break;
       case UNAuthorizationStatusNotDetermined:
           NSLog(@"Undetermined");
           break;
       default:
           break;
       }
       }];      
   }else{
       if UIApplication.shared.isRegisteredForRemoteNotifications {
           NSLog(@"Status Denied");
       } else {
           NSLog(@"Status Authorized");
       }
   }
}
 
Upvote 0
Top