OGeek|极客世界-中国程序员成长平台

标题: ios - ios7如何在后台运行进程 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 21:09
标题: ios - ios7如何在后台运行进程

我想在前台和后台连续运行我的进程。我已经实现了以下代码

self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
                                                    target:self
                                                  selectorselector(repeatedMethod)
                                                  userInfo:nil
                                                   repeats:YES];

self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    NSLog(@"Background handler called. Not running background tasks anymore.");
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
    self.backgroundTask = UIBackgroundTaskInvalid;
}];

在前台很好,但在后台进程只运行了 5 分钟,并且运行时间不超过 5 分钟。但我希望它即使在后台也能连续运行。请帮助。



Best Answer-推荐答案


发生这种情况,因为完成处理程序在 5 分钟后被调用。在使用 UIBackgroundModes 之一之前,您无法在 iOS 中无限期地运行后台进程。这也取决于如果您在应用程序中使用它,您必须提供 BackgroundMode 的功能,否则苹果会拒绝它。

例如,如果您使用“VoiP”BackgroundMode,您的应用程序应提供“VoiP 服务”,否则将被拒绝

关于ios - ios7如何在后台运行进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22756480/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4