Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

OnAuthChange block not called #242

Open
SandeepAggarwal opened this issue Jul 4, 2017 · 2 comments
Open

OnAuthChange block not called #242

SandeepAggarwal opened this issue Jul 4, 2017 · 2 comments

Comments

@SandeepAggarwal
Copy link

SandeepAggarwal commented Jul 4, 2017

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();
         }
     }
 }];`
@royherma
Copy link

same for me, were you able to resolve?

@SandeepAggarwal
Copy link
Author

SandeepAggarwal commented Aug 1, 2017

@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];
 }]; 

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants