在我们的应用程序中,用户将在开始工作时打卡。如果用户忘记打卡退出,我们将不得不在24小时后自动为他打卡退出。应用程序可能不会处于活动/后台状态这么长时间。它可能会被终止。所以我们的想法是发布一个本地通知,通过它在后台执行代码来让他退出。此通知必须是静默通知。但我们从研究中得到的理解是,本地通知不能保持沉默。那么,有没有其他方法可以实现这一点呢?或者我们实际上可以安排一个静默的本地通知吗?
class func generateLocalNotificationWith(timeInterval : TimeInterval, title : String, message : String, mobileTimeClockId: Int)
{
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
//adding title, subtitle, body and badge
content.title = title
content.body = message
let userInfoDictionary = ["badge":"0","content-available": "1"]
let dict = ["aps": userInfoDictionary, "MobileTimeClockId": mobileTimeClockId] as [String : Any]
content.userInfo = dict
//getting the notification trigger
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterval, repeats: false)
//getting the notification request
let request = UNNotificationRequest(identifier: "SimplifiedIOSNotification", content: content, trigger: trigger)
//adding the notification to notification center
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}发布于 2018-07-25 17:20:02
如果您希望通知保持静默并执行后台工作,则它必须是推送通知。本地通知在没有用户交互的情况下无法唤醒您的应用程序。
做你想做的事情的最好方法是在用户离开工作场所时使用核心位置区域监控来唤醒你的应用。地域监控可以在后台静默唤醒你的应用,让你做一些工作。问题是,它不是百分之百确定它将被触发,用户将需要接受后台位置权限。
https://stackoverflow.com/questions/51515005
复制相似问题