任何人都可以帮助我在“设置”>“通知”>“我的应用”下显示“应用通知”设置,该选项类似于附件图像。
答案 0 :(得分:0)
要链接到您的自定义通知设置屏幕,当您在应用程序委托中请求通知权限时,必须将ProvidesAppNotificationSettings设置为UNAuthorizationOption
。
在didFinishLaunchingWithOptions
中,添加以下代码:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound, .providesAppNotificationSettings]) { ... }
当用户选择以任何一种方式进入您的通知设置时,还必须确保处理回调。您的应用程序委托或应用程序委托的扩展必须符合协议UNUserNotificationCenterDelegate
,以便随后可以实现以下回调方法:
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
let navController = self.window?.rootViewController as! UINavigationController
let notificationSettingsVC = NotificationSettingsViewController()
navController.pushViewController(notificationSettingsVC, animated: true)
}