在swiftUI上关闭通知
苹果文档说我可以通过调用此函数来关闭通知:在swiftUI上关闭通知,swift,push-notification,apple-push-notifications,swiftui,Swift,Push Notification,Apple Push Notifications,Swiftui,苹果文档说我可以通过调用此函数来关闭通知:unregisterForRemoteNotifications() 所以我制作了一个按钮,可以像这样调用该函数:button(“Hold”){unregisterForRemoteNotifications() } 但Xcode向我显示此错误消息“使用未解析标识符”unregisterForRemoteNotifications 如何修复此错误? 谢谢:)这是一个好主意。您应该通过UIApplication.shared.unregisterForRe
unregisterForRemoteNotifications()
所以我制作了一个按钮,可以像这样调用该函数:button(“Hold”){unregisterForRemoteNotifications()
}
但Xcode向我显示此错误消息“使用未解析标识符”unregisterForRemoteNotifications
如何修复此错误?
谢谢:)这是一个好主意。您应该通过UIApplication.shared.unregisterForRemoteNotifications()调用它。
因此,您的代码将如下所示:
Button(action: {
UIApplication.shared.unregisterForRemoteNotifications()
}) {
Text("Perform Action")
}
如果使用UNUserNotificationCenter,您可以通过以下方式取消对挂起通知的订阅:UNUserNotificationCenter.current()。removeAllPendingNotificationRequests()
,
要删除已交付的,请使用unuservicentcenter.current().removeAllDeliveredNotifications()