Friday, July 26, 2024
HomeiOS Developmentios - corroct get notification permission in Objc?

ios – corroct get notification permission in Objc?


I’ve a option to get push permissions.
However what I get each time will not be the right worth.
How can I rewrite this technique?
My push permission has been enabled, nevertheless it nonetheless prints out 555 first after which 111.
However after I name this technique outdoors, I’ve already obtained False first.
How can I make the entire technique regular?

- (BOOL)getNotificationPermission
{
    __block BOOL hasPermission;

    UNUserNotificationCenter *heart = [UNUserNotificationCenter currentNotificationCenter];
    [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings){

        switch (settings.authorizationStatus) {
            case UNAuthorizationStatusAuthorized:
                hasPermission = YES;
                NSLog(@"111");
                break;
            case UNAuthorizationStatusDenied:
                hasPermission = NO;
                NSLog(@"222");
                break;
            case UNAuthorizationStatusNotDetermined:
                hasPermission = NO;
                NSLog(@"333");
                break;
            default:
                hasPermission = NO;
                NSLog(@"444");
                break;
        }
    }];

    NSLog(@"555");

    return hasPermission;
}

Log

555
111



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments