简体   繁体   English

Swift - 在后台应用程序中接收本地通知时执行功能

[英]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.

相关问题 当应用程序在后台启动并发出本地通知时执行代码 - Execute code when app in background and a Local Notification fires 在后台接收本地通知时如何播放音乐 - How to play music when receive local notification on background 无法访问时本地通知,并且应用程序在后台 - local notification when not reachable and app in background 在应用程序处于后台状态时获取本地通知? - Get the local notification when the app is in background state? 当应用程序在后台时处理本地通知 - Handle local notification when app is in background 当应用程序在后台运行时,swift 4通知不出现 - swift 4 notification not appearing when app is in background 应用程序在后台 swift 3 时的远程推送通知 - remote push Notification when app is in background swift 3 Swift-交付应用程序上的本地通知图标徽章编号更新处于后台 - Swift - Local notification icon badge number update on deliver App is in background 当应用程序在前台时,iOS Swift 接收推送通知 - iOS Swift Receive Push Notification When App in Foreground (iOS MPMusicPlayerNotification)如何在应用程序处于后台时接收通知 - (iOS MPMusicPlayerNotification) how to receive notification when app is in the background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM