【发布时间】:2018-08-22 15:46:51
【问题描述】:
我正在尝试在我的应用中设置推送通知。
我在以前的 xcode 项目中打开了推送通知,它运行良好。这是我的代码..
//add push notifications every 5 hours
func pushNotifications() {
let pushNotification = UNMutableNotificationContent()
pushNotification.title = "Time to track your water useage!"
pushNotification.badge = 1
let minute:TimeInterval = 60.0
let hour:TimeInterval = 60.0 * minute
let eighthDay:TimeInterval = 5 * hour
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: eighthDay, repeats: true)
let request = UNNotificationRequest(identifier: "timerDone", content: pushNotification, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
我在我的 viewdidload 函数中调用它
我做错了什么?
【问题讨论】:
-
UNMutableNotificationContent创建一个本地通知。这不是推送通知。 -
@vadian 哦。那为什么我的本地通知不起作用?
-
你需要实现 willPresent 并返回所需的类型,因为当应用程序在前台时通知不会显示默认值,还要确保你请求了权限,看这里thomashanning.com/…
-
谢谢@Sh_Khan 我会检查一下
标签: ios swift xcode push-notification apple-push-notifications