nickoneill / PermissionScope

Intelligent iOS permissions UI and unified API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OnAuthChange block not called

SandeepAggarwal opened this issue · comments

OnAuthChange block is not getting called in case of notification permission

    ` PermissionScope* permissionScope = [PermissionScope new];
     switch ([permissionScope statusNotifications])
     {
             case PermissionStatusAuthorized:
               if (authorizedBlock)
              {
                    authorizedBlock();
              }
              return;
        
             case PermissionStatusUnknown:
               [permissionScope requestNotifications];
                break;
    
              case PermissionStatusUnauthorized:
             case PermissionStatusDisabled:
             if (deniedOrDisabledBlock)
            {
                deniedOrDisabledBlock();
            }
            return;
   }

@weakify(permissionScope);
[permissionScope setOnAuthChange:^(BOOL authorized, NSArray<PermissionResult *> * _Nonnull results)
 {
     @strongify(permissionScope);
     NSLog(@"status: %ld",[permissionScope statusNotifications]);
     
     if ([permissionScope statusNotifications] == PermissionStatusUnauthorized)
     {
         if (deniedOrDisabledBlock)
         {
             deniedOrDisabledBlock();
         }
     }
     else if ([permissionScope statusNotifications] == PermissionStatusAuthorized)
     {
         if (authorizedBlock)
         {
             authorizedBlock();
         }
     }
 }];`

same for me, were you able to resolve?

@royherma Yes, I was able to use a workaround to solve this issue:

//setOnAuthChange: is not being called (bug) so this workaround

@weakify(permissionScope);
 [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note)
 {
          @strongify(permissionScope);
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), 
         dispatch_get_main_queue(), ^
        {
               if ([permissionScope statusNotifications] == PermissionStatusUnauthorized || 
               [permissionScope statusNotifications] == PermissionStatusDisabled)
             {
                     if (deniedOrDisabledBlock)
                    {
                          deniedOrDisabledBlock();
                    }
             }
             else
             {
                    if (authorizedBlock)
                    {
                         authorizedBlock();
                    }
              }
        });
          [[NSNotificationCenter defaultCenter] removeObserver:self];
 }];