iOS - Access SQLite DB and show notification every few days from the background

问题

我的SQLite DB中有此内容。我需要在另一个之后透露每一块内容。

table screenshot

对于我需要每隔几天访问SQLite文件(如上表所示),显示内容,然后显示新内容可用的通知。


解决思想

A)背景获取
阅读后为您的应用程序提供背景策略苹果,我并不完全肯定要去什么。通常,我的任务听起来像“更新内容”一个。为此,BackgroundFetchEEMS是预期的工具。

问题:从互联网上看其他来源,听起来并不像它一样(由Apple Dev表示):

https://developer.apple.com/forums/thread/103204:

This isn’t really the intended use case for background fetch. The idea behind background fetch is that the system learns when the user is using the app and, if the user is regularly using it at specific times, the system sends the app a background fetch event before that time so that it can refresh.

从中,这意味着要运行Periotiod,虽然我需要的是不规律的,只有每隔几天。我将如何将其设置为每隔几天触发?

B)在第一次开始时计划所有通知
如果没有别的,我也可以在第一个App的第一个开始时安排所有通知(或第一次接受“通知对话框)。然后他们在他们应该的日期究竟脱落。

PROBLE:如果用户单击通知后,内容会显示逻辑将运行并从SQLite中获取内容。如果用户没有单击通知怎么办?


我还有其他选择吗?
I don’t need an exact hour of execution, just that it happens on that day at all. Is it possible at all?

There is this sample code 使用后台任务重新编程和维护您的应用程序我发现的Apple,但它使用旧的应用程序委托结构,这有点难以追随,就像从SWIFTUI开始的人一样努力。

I’m not if I understand your concern about option (b). If the user doesn’t open the notification, the next scheduled one should still fire off on the desired schedule.ROB
But, as you’ve deduced, background fetch is not intended for this use-case. Besides, it is run at the sole discretion of the OS and you have no control over when it’s run (even what days). If user uses your app, it’s more likely to run more frequently, but if they don’t run your app, it will run less frequently.ROB
@ Rob问题是,无论用户是否打开它,仍应显示内容。如果他没有点击它,但稍后打开该应用程序,那么就不会有任何新内容。这将需要在启动和比较上进行双重逻辑检查与DB。big_chair
@ Rob,我不认为这是一个激进的,这是每2,3甚至5天的一个通知。而且它是一个自我改善的应用程序,频繁使用是任何进展的基础。但这将是另一个方法b),禁用一次,它永远不会揭示新内容。BIG_CHAIR
Re aggressiveness, once you lose someone, you’ve probably lost them forever, so it’s your call. Re “content should still be revealed regardless if whether user opens it or not”, I’m unclear where you’re revealing it if the user doesn’t tap on the notification and doesn’t launch the app. Perhaps you can edit your question and clarify…ROB

回答 0