gpt4 book ai didi

ios - 有没有办法在没有用户或服务器干预的情况下唤醒 iOS 中暂停的应用程序

转载 作者:IT王子 更新时间:2023-10-29 08:19:40 24 4
gpt4 key购买 nike

有没有办法不使用“显着变化位置服务”来唤醒 iOS 应用程序?

我需要在没有服务器或用户干预的情况下唤醒我的应用程序类似于闹钟的功能,您会在该起床时收到提醒弹出窗口。

UILocalNotification - 不会工作,因为它需要用户和服务器干预。

静默推送通知 - 将不起作用,因为您无法将本地通知作为静默推送通知发送。这些只能由服务器发送。这意味着它需要服务器干预。

Background Fetch - 无法工作,因为无法保证触发时间。

我错过了什么吗?

最佳答案

编辑:您已调整问题以明确声明“无需用户或服务器干预”。

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

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

UILocalNotification

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

静默推送通知

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

有效载荷看起来像这样:

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

并且您将使用特定的委托(delegate)方法在您的应用委托(delegate)中接收它:

- (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 和 background execution documentation有关此方法的更多信息。

Multi-Tasking Objc.io 上的文章也是这种方法的良好开端。

后台获取

如果你读入 background modes来自 Apple 的文档 可以使用 UIBackgroudnModes 取值让您的应用程序被机会性唤醒,并有时间下载或更新其数据。

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

Apps that need to check for new content periodically can ask the system to wake them up so that they can initiate a fetch operation for that content. To support this mode, enable the Background fetch option from the Background modes section of the Capabilities tab in your Xcode project.

关于ios - 有没有办法在没有用户或服务器干预的情况下唤醒 iOS 中暂停的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35388086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com