Ios 在Swift中禁用推送通知中的横幅

Ios 在Swift中禁用推送通知中的横幅,ios,swift,push-notification,apple-push-notifications,onesignal,Ios,Swift,Push Notification,Apple Push Notifications,Onesignal,对于使用OneSignal SDK的通知服务im。是否可以从代码更改通知设置? 我想只允许通知中心,徽章,声音 但是当我试着设定它的时候 class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOpti

对于使用OneSignal SDK的通知服务im。是否可以从代码更改通知设置? 我想只允许通知中心,徽章,声音

但是当我试着设定它的时候

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
       UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .badge]) { (success, error) in
            print(self,#function,success)
        }
        UNUserNotificationCenter.current().delegate = self
        
        return true
    }
        
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.sound,.badge])
    }

}
通知出现了,并以横幅和锁屏显示

我手动设置,效果非常好。


从代码进行设置非常好。

否,您可以先请求特定的通知类型权限,但从该点开始,用户控制通知设置。否,您可以先请求特定的通知类型权限,但从该点开始,用户控制通知设置。