SwiftUI-通知和移动到新视图



是否可以在按下按钮时生成通知,并且单击通知会在选项卡视图中选择不同的选项卡?

或者,如果这不可能,请将选项卡"按钮"更改为不同的颜色,以便用户知道在生成通知后导航到该选项卡?提前谢谢。

这就是你的做法-

请求权限

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
if success {
print("All set!")
} else if let error = error {
print(error.localizedDescription)
}
}

日程通知

let content = UNMutableNotificationContent()
content.title = "Feed the cat"
content.subtitle = "It looks hungry"
content.sound = UNNotificationSound.default
// show this notification five seconds from now
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
// add our notification request
UNUserNotificationCenter.current().add(request)

您可以按照本教程了解更多详细信息

最新更新