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

Discussion in 'iOS Questions' started by fbritop, Jul 10, 2018.

  1. fbritop

    fbritop Active Member Licensed User

  2. Erel

    Erel Administrator Staff Member Licensed User

    This is the equivalent B4i code:
    Code:
    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
     
  3. fbritop

    fbritop Active Member Licensed 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


    Code:
    #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");
           }
       }
    }
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You asked how to implement the swift solution in B4i and I posted it.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice