如何设置 UNAlertStyle?

How to set UNAlertStyle?

UNAlertStyle 确定通知是显示为横幅还是警报。可以使用 getNotificationSettingsWithCompletionHandler 查看应用程序的当前授权设置。如果请求(并允许)UNAuthorizationOptionAlert,则默认样式似乎是 UNAlertStyleBanner,但除了用户进入通知设置之外,我找不到其他方法来指定将本地通知显示为警报。

请求 UNAuthorizationOptionAlert 的设置对我来说没有意义。以下测试应用程序请求警报和声音的授权,然后 NSLog 的结果通知设置:

#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate () {
    UNUserNotificationCenter* center;
}
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    center = [UNUserNotificationCenter currentNotificationCenter];

    // request authorization for sounds and alerts
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound)
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              NSLog(@"requestAuthorizationWithOptions granted: %i", granted);

                              // check resulting notification settings
                              [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
                                  NSLog(@"getNotificationSettings: %@", settings);
                              }];
                          }];

    return YES;
}

生成的设置显示警报 NotSupported(但未请求的 CarPlay 已启用!):

authorizationStatus: Authorized, 
notificationCenterSetting: Enabled, 
soundSetting: Enabled, 
badgeSetting: NotSupported, 
lockScreenSetting: Enabled, 
alertSetting: NotSupported, 
carPlaySetting: Enabled, 
alertStyle: Banner

有什么建议吗?

but I can find no way to specify that a local notification be presented as an alert other than the user going into the notificatinon settings

你找不到它,因为它不存在。横幅是默认的通知提醒格式,您的应用无法更改它。 UNAlertStyle 不可由应用程序设置;它报告用户的设置,仅此而已。