简体   繁体   中英

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.

If I use the userNotificationCenter (_: didReceive: withCompletionHandler :) function only when the user taps the notification.

If I use the userNotificationCenter (_: willPresent: withCompletionHandler :) function I can run only when the application is running.

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允许应用程序安排活动在后台运行,而不必强迫用户打开应用程序并让它在前台运行。“

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM