[英]Swift - Execute function when receive Local Notification in app in background
I am creating an app that the user schedules some tasks in a certain time interval and the application sends local notifications to alert the user. 我正在创建一个应用程序,用户在某个时间间隔内安排某些任务,并且应用程序发送本地通知以提醒用户。
I am using UNUserNotificationCenter
to schedule the notifications and everything is working normally but I need every time the notification is received, execute a function that would save the notification data in a database. 我正在使用UNUserNotificationCenter
来安排通知,一切正常,但我每次收到通知时都需要执行一个将通知数据保存在数据库中的功能。
If I use the userNotificationCenter (_: didReceive: withCompletionHandler :)
function only when the user taps the notification. 如果我仅在用户点击通知时使用userNotificationCenter (_: didReceive: withCompletionHandler :)
函数。
If I use the userNotificationCenter (_: willPresent: withCompletionHandler :)
function I can run only when the application is running. 如果我使用userNotificationCenter (_: willPresent: withCompletionHandler :)
函数,我只能在应用程序运行时运行。
With these two options above I can not save to the database when the notification arrives with the application in the background and the user does not click. 使用上面的这两个选项,当应用程序在后台运行并且用户没有单击时,我无法保存到数据库。 Does anyone know of any other function that I can call this case? 有谁知道我可以称这种情况的任何其他功能? OR a way of executing a function when the notification is received. 或者是在收到通知时执行功能的方法。
你不能:( UserNotification是为了向用户显示一些信息,而不是在应用程序中安排任务。希望这将在iOS 13中改变 - 正如Apple所说:“iOS 13为平台增加了一个新的后台任务API允许应用程序安排活动在后台运行,而不必强迫用户打开应用程序并让它在前台运行。“
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.