在iOS上的后台重复运行代码 [英] running code repeatedly in background on ios

查看:82
本文介绍了在iOS上的后台重复运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作类似闹钟的应用.应该在大约30分钟的时间内每10-60秒向用户通知一次振动和声音.最好的方法是什么?在前台执行此操作很容易,但是如何继续在后台运行计划的代码?我可以使用本地通知,但是在请勿打扰"模式下,用户不会收到它们.

I'm making an alarm clock-like app. The user should be notified with a vibration and a sound every 10-60 seconds over a period of about 30 minutes. What is the best approach for this? It's easy enough doing it in the foreground, but how can i continue to run scheduled code in the background? I could use local notifications, but the user doesn't receive them when in "do not disturb" mode.

推荐答案

您应该查看有关后台执行的文档:实施长期运行的后台任务.无论如何,提交评论总是有可能批准您的应用.

You should review the documentation about background execution: Background Execution and Multitasking. There are multiple ways of consistently running code in the background, but your app has to meet certain guidelines to use them--in your case, I don't think your app neatly falls into any of the categories Apple describes in Implementing Long-Running Background Tasks. There's always the possibility the submission reviews could approve your app anyway.

为避免潜在的应用程序拒绝,您应该使用本地通知来实现您的应用程序,并在您的应用程序中包含一条警告,要求用户禁用请勿打扰"以使其正常运行.不幸的是,用户没有办法从DND中排除应用程序,也没有公共API来操纵DND.

To avoid potential app rejection, you should implement your app using local notifications, and include a warning in your app that users should disable "Do Not Disturb" for it to function correctly. Unfortunately, there isn't a way for users to exclude apps from DND, nor is there a public API to manipulate DND.

这篇关于在iOS上的后台重复运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆