iOS的运行code每天一次 [英] iOS Run Code Once a Day

查看:90
本文介绍了iOS的运行code每天一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此应用程序背后的想法很简单:下载文件。不过这个应用程序将是人谁不经常上网的范围内,所以我需要知道的,说上午9:00,将文件下载到硬盘驱动器。将有应用程序中的一个按钮来手动做得一样好,但我已经得到了该工作。

据我了解,这将是困难的,如果它甚至有可能。我知道,iOS不喜欢多任务,但我也知道,它确实允许后台定时器功能。我愿意接受任何形式的建议,任何人都可能要做到这一点,即使这意味着写一个单独的应用程序。谢谢你。

编辑:我看到有使用通知,甚至可能日历工作的可能性。这一类的想法,也表示欢迎。

编辑2:我也看了一些有关外部服务器发起的应用程序,但它没有给出说明


解决方案

下面是关于后台执行和通知和定时器等有关的应用程序安排一些活动,定期发生的情况。


  1. 应用程序不能在后台执行,除非:


    1. 它要求从OS额外的时间来做到这一点。这是使用 beginBackgroundTaskWithExpirationHandler 完成。它没有指定(故意)苹果这个额外的时间,但在实践中它有多长10分钟左右。


    2. 这是应用程序有一个背景模式,模式有:VOIP,声音,位置,书报摊。即使有这些类型的应用程序不能没有一些限制执行中的一个。本次讨论的其余部分假定应用程序没有后台模式。



  2. 当一个应用程序被暂停它不能做任何事情来唤起直接本身。它不能previously已经安排了的NSTimer,它不能使用像performSelector:afterDelay。等。

    只有这样应用程序可以活跃起来是如果用户没有东西,将其激活。用户可以从通过下面的做到这一点:


    1. 直接从图标,启动程序


    2. 启动应用程序响应本地通知,这是$ P $由应用pviously计划,而这是积极的。


    3. 启动响应由服务器发送一个远程通知的应用程序。


    4. 其他几个:如如果应用程序被注册到处理通过URL网址发射发射;或者,如果其注册为有能力处理特定类型的内容。



如果一个应用程序是在前台当本地/远程通知火灾然后应用程序直接接收它。

如果应用程序是不是目前在前台当本地/远程通知火灾然后应用程序不接收它。有执行,没有code时通报火灾!

仅当用户选择该通知将该应用被激活,它可以执行

请注意,用户可以禁用通知,或者用于整个设备,或者只为特定应用,在这种情况下,用户将不会看到它们。如果该设备被关闭时,一个通知是因火灾则它丢失。

The idea behind this app is very simple: download a file. However this app will be for people who are not always within internet access range, so I need it to know that at, say 9:00 AM, to download a file to the hard drive. There will be a button within the app to do it manually as well, but I've already got that working.

As I understand it, this will be difficult if it is even possible. I know that iOS doesn't like multitasking, but I am also aware that it does allow for background timer functions. I am open to any sort of suggestions anyone might have to accomplish this, even if it means writing a separate app. Thanks.

Edit: I see there is the possibility of working with Notifications, or even maybe the Calendar. Ideas in that category as also welcomed.

Edit 2: I also read something about an external server initiating an app, but it gave no description.

解决方案

Here's the situation regarding background execution and notifications and timers etc. in relation to an app scheduling some activity to happen periodically.

  1. An app cannot execute in the background unless:

    1. It requests extra time from the OS to do so. This is done using beginBackgroundTaskWithExpirationHandler. It is not specified (intentionally) by Apple how long this extra time is, however in practice it is around 10 minutes.

    2. An app has a background mode, the modes are: voip, audio, location, newstand. Even if it has one of these types an app cannot execute without some restrictions. The rest of this discussion assumes the app does not have a background mode.

  2. When an app is suspended it cannot do ANYTHING to rouse itself directly. It cannot previously have scheduled an NSTimer, it cannot make use of something like performSelector:afterDelay. etc.

    The ONLY way the app can become active again is if the USER does something to make it active. The user can do this from via of the following:

    1. Launch the app directly from its icon

    2. Launch the app in response to a local notification that was previously scheduled by the app while it was active.

    3. Launch the app in response to a remote notification sent by a server.

    4. A few others: such as URL launching if the app is registered to deal with launching via a url; or if its registered to be capable of dealing with a certain type of content.

If an app is in the foreground when a local/remote notification fires then the app receives it directly.

If the app is not currently in the foreground when a local/remote notification fires then the app DOES NOT receive it. There is no code that is executed when the notification fires!

Only IF the user selects the notification will the app become active and it can execute.

Note that the user can disable notifications, either for the entire device, or just for a specific application, in which case the user will never see them. If the device is turned off when a notification is due to fire then it is lost.

这篇关于iOS的运行code每天一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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