干预的情况下唤醒

干预的情况下唤醒

本文介绍了有没有办法在没有用户或服务器干预的情况下唤醒iOS中暂停的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在不使用重要更改位置服务的情况下唤醒iOS应用程序?

Is there way to wakeup iOS app without using "The significant-change location service"?

我需要在没有服务器或用户干预的情况下唤醒我的应用程序
类似于闹钟的一些东西,当你醒来的时候你得到一个警告弹出窗口。

I need to wakeup my app without server or user interventionSome thing similar to Alarm clock wherein you get an alert popup when its time to wakeup.

UILocalNotification - 无法使用,因为它需要用户和服务器干预。

UILocalNotification - Won't work since it would need user and sever intervention.

无声推送通知 - 由于您无法将本地通知作为静音推送通知发送,因此无法正常工作。这些只能由服务器发送。这意味着它需要服务器干预

Silent Push Notifications - Wont work since you cannot send local notifications as Silent push notifications. These can only be sent by Server. Which means it would need Server intervention

后台获取 - 由于没有保证的触发时间而无法工作

Background Fetch - Wont work since there is not guaranteed trigger time

我错过了什么吗?

推荐答案

编辑:您已调整问题以明确说明'没有用户或服务器干预'。

不,据我所知,设计iOS没有提供明确的方法来唤醒您的应用程序确定未来的时间。您可以在后台继续执行长时间运行的任务,机会性地获取更新的内容,提醒用户在需要时重新打开您的应用,并在需要时使用静音推送通知提示前两个。

No, As far as I'm aware by design iOS does not provide an explicit way to wake up your app at determinate time in the future. You can continue long running tasks while in the background, opportunistically fetch updated content, remind users to re-open your app if need be and prompt the first two with silent push notifications if need be.

以下是上述三个选项的一些提示:

Here are some hints on the three options above:

UILocalNotification

最简单的方法是安排一些未来的某个时间,但为了唤醒您的应用程序,您需要与通知进行交互。这可能不是你想要的。

The easiest way is to schedule some UILocalNotifications at a time in the future but in order to wake up your app you need to interact with the notification. This may not be what you want.

无声推送通知

iOS 7之后的另一个选择是 content-available 或静默推送通知。您为此类通知设置了特定的有效负载,如果您的应用具有正确的 UIBackgroundMode 值设置,它将以静默方式传送到您的应用:

Another option since iOS 7 is a content-available or silent push notification. You setup a particular payload for this kind of notification and if your app has the correct UIBackgroundMode value setup it will be delivered to your app silently:

有效负载看起来像这样:

The payload would look something like this:

{
    "aps" : {
        "content-available" : 1
    },
    "content-id" : 42
}

你会在你的app委托中使用特定的委托方法收到它:

And you would receive it in your app delegate with a specific delegate method:

- (void)         application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
      fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"Remote Notification userInfo is %@", userInfo);

    NSNumber *contentID = userInfo[@"content-id"];
    // Do something with the content ID
    completionHandler(UIBackgroundFetchResultNewData);
}

然后,您可以使用此商机下载内容或在需要时快速更新您的应用,看看UIBackgroundModes和有关此方法的更多信息。

You can then use this opportunity download content or update your app quickly if need be, take a look at the UIBackgroundModes and background execution documentation for more info on this approach.

文章也是这种方法的良好开端。

The Multi-Tasking article at Objc.io is also a good start for this approach.

后台提取

如果您阅读文档可以使用您的应用的 UIBackgroudnModes 值获取机会性地醒来,并有时间下载或更新它的数据。

If you read into the background modes documentation from Apple it's possible using the UIBackgroudnModes value fetch for your app to be woken up opportunistically and given time to download or update it's data.

Apple关于此的文档提到了它的用例:

Apple's documentation on this mentions it's use case:

这篇关于有没有办法在没有用户或服务器干预的情况下唤醒iOS中暂停的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:59