2
   UNUserNotificationCenter *notificaitnCenter = [UNUserNotificationCenter currentNotificationCenter];
    [notificaitnCenter requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionProvidesAppNotificationSettings completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];

            });

        }
    }];

实现这段代码后,我也看不到通知设置选项。

4

1 回答 1

1
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")){
    UNUserNotificationCenter *notifiCenter = [UNUserNotificationCenter currentNotificationCenter];
    notifiCenter.delegate = self;
    [notifiCenter requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if( !error ){

            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });

        }
    }];

}
else
{
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}

可能是ios版本不支持试试这段代码

于 2020-02-05T10:48:52.487 回答