让应用程序在后台无限运行(对于 Cydia 应用程序)
我不介意使用私有 API 或 Apple 不喜欢的任何类型,但更喜欢一种快速的解决方案,而不是像在后台播放静音或 swizzling 之类的东西。
显然这不适用于应用程序商店,所以请不要说教:)
那么如何在没有“背景程序”之类的限制的情况下在后台运行呢?除了一些将人们指向不同方向的答案之外,我没有找到答案,但也许从那时起就已经有人设法挖掘它了。
I don't mind using private API's or anything of the kind that Apple doesn't like, but would prefer a quick solution that doesn't stuff like playing silence in the background or swizzling.
Obviously this isn't for the app store so please no lecturing :)
So how do you run in the background without any restrictions like "backgrounder"? I didn't manage to find an answer besides some that point people to different directions, but maybe since then someone managed to dig it up already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:
此解决方案似乎不再足够(〜iOS 7+或7.1+)。我将保留原始答案以供历史参考,以防万一它有助于基于这个过时的解决方案生成未来的解决方案:
这取决于您所说的应用程序的含义。如果您谈论的是非图形后台服务,那么您需要的是启动守护程序。 请参阅此处了解如何创建启动守护程序。
如果您有一个普通的 UI 应用程序,但当用户按下主页按钮时,您希望它在后台无限时间地保持唤醒状态,然后您可以在应用程序的 Info.plist 文件中使用一些未记录的后台模式:
然后,当 iOS 准备好将您的应用程序置于后台时(例如,用户按 home按钮),您可以在应用程序委托中执行此操作:
通常,iOS 只给您最多 10 分钟的时间让您的 UI 应用程序在后台运行。使用未记录的后台模式,您将能够在超过 10 分钟限制后保持活力。
注意:这不需要需要与 MobileSubstrate 挂钩。如果您使用第二种方法(未记录的后台模式),那么它确实需要将您的应用程序安装在
/Applications/
中,而不是在正常的沙箱区域中(/var/mobile/Applications/
)。Update:
This solution no longer appears to be sufficient (~ iOS 7+ or 7.1+). I'm leaving the original answer for historical reference, and in case it helps produce a future solution based on this obsolete one:
It depends on what you mean by app. If you're talking about a non-graphical background service, then what you want is a Launch Daemon. See here for how to create a launch daemon.
If you have a normal UI application, but when the user presses the home button, you want it to stay awake in the background for an unlimited time, then you can use some undocumented Background Modes in your app's Info.plist file:
Then, when iOS is ready to put your app into the background (e.g. user presses home button), you can do this, in your app delegate:
Normally, iOS only gives you up to 10 minutes for your UI application to work in the background. With the undocumented background mode, you'll be able to keep alive past that 10 minute limit.
Note: this does not require hooking with MobileSubstrate. If you're using the second method (undocumented Background Modes), then it does require installing your app in
/Applications/
, not in the normal sandbox area (/var/mobile/Applications/
).根据您的“应用程序”要执行的操作,您可以挂钩 MobileSubstrate。这将加载 SpringBoard 并本质上“在后台”运行。
如果你想编写一个实际的应用程序,那么你也可以编写一个“动态库”,它将由MobileSUbstrate加载SpringBoard。您可以使用 NSNotificationCenter 在此 dylib 和您的应用程序之间来回通信;创建和发布通知。
Depending on what your "app" is going to do, you can hook MobileSubstrate. This will load with SpringBoard and essentially run "in the background".
If you want to write an actual application, then you can also write a "Dynamic Library" which will be loaded with SpringBoard by MobileSUbstrate. You can talk back and forth between this dylib and your app by using
NSNotificationCenter
; creating and posting notifications.