如何保持我的应用程序超过10分钟。在后台? [英] How to keep my app longer than 10 min. in the background?

查看:416
本文介绍了如何保持我的应用程序超过10分钟。在后台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在iOS上,后台应用程序只能在运行

I know that in iOS, background apps can only be running


  • 有限长度的任务(10分钟)

  • 位置更新

  • 的VoIP

  • 音频

有没有我的应用程序,以避免被10分钟后,被终止的一种方法。在后台?我不会提交我的应用程序应用商店,所以一切都是允许的(私人的框架,使用GPS,即使我并不需要它)我知道苹果不推荐,但它只是为了监控目的。我需要它在不限制运行。

Is there a way for my application to avoid being terminated after being 10 min. in the background? I will not be submitting my app to the app store, so everything is allowed (private frameworks, using the gps even if I don't need it) I know apple does not recommend this, but it is just for monitoring purposes. I need it to be running without a limit.

我探索了几种可能性,包括网络电话,但只给了我30秒每隔10分钟,这是不够的。我也看到这篇文章:
iPhone - 一个后台轮​​询事件
其中JackPearse规定的方式复活使用VoIP的30秒任务该十分钟有限长度的任务。但我不希望我的任务开始和结束每10分钟,它必须运行时间可持续。
我也试过他的UP​​DATE2,但它不是为我工作。
我甚至试图与GSEvent.type 2012年,这似乎是一个结束我的后台任务,但没有运气拦截的UIEvent。奇怪的是,我的后台任务从来没有当我包含X code打开和调试,但是当我不(单独测试模拟器),10分钟后它最终结束了。

I explored several possibilities including the VoIP , but it only gives me 30 seconds every 10 minutes, which is not enough. I also read this post: iPhone - Backgrounding to poll for events in which JackPearse specified a way to "revive" the 10 minute finite-length task using the VoIP 30 second task. But I don't want my task to start and end every 10 minutes, it must run continuosly. I also tried his UPDATE2, but it's not working for me. I even tried intercepting the UIEvent with GSEvent.type 2012, which seemed to be the one ending my background task, but no luck. Strangely, my background task is never ended when I have Xcode opened and debugging, but when I don't (test the simulator alone) it ends after 10 minutes.

推荐答案

我发现了如何通过在后台持续播放歌曲让我的应用程序在后台的时间超过10分钟。
在AppDidFinishLauching:

I found out how to keep my Application in the background for longer than 10 minutes by continuously playing a song in the background. On the AppDidFinishLauching:

[[AVAudioSession sharedInstance] setActive:YES error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
NSURL *url = [NSURL fileURLWithPath:...]; //Song URL
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

player.numberOfLoops = -1;
[player play];

在AppDidEnterBackground可以执行在后台的选择,它可以永远持续下去。该应用程序将不会被打断,你可以检查的UIApplication backgroundtimeRemaining,看看它永远不会减少。

In the AppDidEnterBackground you can perform a selector in background, which can last forever. The App will not be interrupted, you can check UIApplication backgroundtimeRemaining and see it never decreases.

当然,声明应用程序作为plist中后台音频应用。

Of course, declare the app as a background audio App in the plist.

这篇关于如何保持我的应用程序超过10分钟。在后台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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