I am trying to update to NSUserNotifications.
I have changed how my code is written and changed where it is place but the same thing keeps happening.
In my AnotherViewController.h
#import <UserNotifications/UserNotifications.h>
#import <UserNotifications/UNUserNotificationCenter.h>
@interface AnotherViewController : UIViewController <UNUserNotificationCenterDelegate>
{
UNAuthorizationOptions UNAuthorizationOptionBadge;;
UNAuthorizationOptions UNAuthorizationOptionAlert;
UNAuthorizationOptions UNAuthorizationOptionSound;
}
@property(readonly, copy) NSString *localizedDescription;
In my AnotherViewController.m
@synthesize localizedDescription;
-(void)viewDidAppear:(BOOL)animated;{
[super viewDidAppear:YES];
NSLog(@"viewDidAppear");
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (@available(iOS 14.0, *)) {
if (settings.authorizationStatus == UNAuthorizationStatusEphemeral) {
NSLog(@"Ephermeral");
}
else if (settings.authorizationStatus == UNAuthorizationStatusProvisional) {
NSLog(@"provisional");
}
else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
NSLog(@"authorized");
}
else if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
NSLog(@"denied");
}
else if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
NSLog(@"Not determined");
[center requestAuthorizationWithOptions:(self->UNAuthorizationOptionBadge|self->UNAuthorizationOptionAlert|self->UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (! error) {
NSLog(@"success");
}
else {
NSLog(@"desc%@",self.localizedDescription);
}
}];
}
}
else {
NSLog(@"earlier");
}
}];
In my log I get Not determined and then success.
if (! error){NSLog(@"success");}
So even though the status is Not determined the app calls the method but does not display the Alert asking for permission.
Still not sure why this is happening.