从服务器发出通知后更新应用程序中的数据 - 即使强行退出?

时间:2017-08-04 17:03:20

标签: ios iphone

我有一个事件注册系统,用户可以在网络应用程序和iOS应用程序中在线注册。这些事件与iPhone上的本地日历同步。

现在我想要实现的是,每当用户在Web应用程序中更改内容时,它将自动更新设备日历。我尝试了push和background fetch,但是当用户强制退出应用程序时,两者都不起作用。有没有办法至少定期在应用程序中运行一些代码来进行更新?

4 个答案:

答案 0 :(得分:3)

您是否尝试过无声通知?您可以在有效负载中包含"content-available" : 1密钥。 iOS会唤醒您的应用并允许您下载一些数据。

Configuring a Silent Notification标题下查看。

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1

答案 1 :(得分:1)

您可以使用PushKit实现此目的。它允许您默默地将应用程序启动到后台,没有可视警报提示,即使您的应用程序被从应用切换器中滑出也会被杀死。

但问题是PushKit仅用于VoIP,watchOS并发症和文件提供程序更新。我不确定Apple是否允许我们将其用于任何其他目的。

所以,如果你不能用PushKit做到这一点,那么除此之外别无他法。

答案 2 :(得分:1)

在没有警报密钥的情况下使用有效负载中的内容

  {
    "aps" = {
        "content-available" : 1
    };
    data = {
        "title" = "Welcome";
        };
   }

答案 3 :(得分:0)

I think silent push notifications will still be delivered and wake your app even if the user force quitted it. Note that push notifications in general are not guaranteed to be delivered though, so always to a sync when you app starts.

If silent push notifications do not work, then there is no way to do this though, as all the local event triggers (such as location updates) do not execute anymore when the user force quits the app.

The real solution here is probably to teach the user that force quitting does not optimize battery life, and in fact in many cases makes battery life even worse. This is a general misunderstanding and teaching the user to not do this does not only benefit yours but also other apps. So if your app relies on not being force quite, it may in deed be a solution to show an explanation screen to the user, explaining him that this harms the experience of the app.