Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在swiftUI上关闭通知_Swift_Push Notification_Apple Push Notifications_Swiftui - Fatal编程技术网

在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()