让应用程序在后台无限运行(对于 Cydia 应用程序)

发布于 2024-12-23 01:25:07 字数 196 浏览 1 评论 0原文

我不介意使用私有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女净妖师 2024-12-30 01:25:07

更新:

此解决方案似乎不再足够(〜iOS 7+或7.1+)。我将保留原始答案以供历史参考,以防万一它有助于基于这个过时的解决方案生成未来的解决方案:


这取决于您所说的应用程序的含义。如果您谈论的是非图形后台服务,那么您需要的是启动守护程序。 请参阅此处了解如何创建启动守护程序

如果您有一个普通的 UI 应用程序,但当用户按下主页按钮时,您希望它在后台无限时间地保持唤醒状态,然后您可以在应用程序的 Info.plist 文件中使用一些未记录的后台模式

<key>UIBackgroundModes</key>
<array>
    <string>continuous</string>
    <string>unboundedTaskCompletion</string>
</array>

然后,当 iOS 准备好将您的应用程序置于后台时(例如,用户按 home按钮),您可以在应用程序委托中执行此操作:

@property (nonatomic, assign) UIBackgroundTaskIdentifier bgTask;


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Delay execution of my block for 15 minutes.
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 15 * 60 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
        NSLog(@"I'm still alive!");
    });

    self.bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        // should never get here under normal circumstances
        [application endBackgroundTask: self.bgTask]; 
        self.bgTask = UIBackgroundTaskInvalid;
        NSLog(@"I'm going away now ....");
    }];
}

通常,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:

<key>UIBackgroundModes</key>
<array>
    <string>continuous</string>
    <string>unboundedTaskCompletion</string>
</array>

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:

@property (nonatomic, assign) UIBackgroundTaskIdentifier bgTask;


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Delay execution of my block for 15 minutes.
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 15 * 60 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
        NSLog(@"I'm still alive!");
    });

    self.bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        // should never get here under normal circumstances
        [application endBackgroundTask: self.bgTask]; 
        self.bgTask = UIBackgroundTaskInvalid;
        NSLog(@"I'm going away now ....");
    }];
}

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/).

贩梦商人 2024-12-30 01:25:07

根据您的“应用程序”要执行的操作,您可以挂钩 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文