App长活

iOS app退到后台经常被杀,重新启动体验很差

2021-05-13  本文已影响0人  余鹤龄

- (void)applicationWillEnterForeground{

    [self endBackgroundTask];

}

- (void)comeToBackgroundMode{

    UIApplication *application = [UIApplication sharedApplication];

    self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{

        [self endBackgroundTask];

    }];

    NSLog(@"计数:bgTask");

}

- (void)applicationDidEnterBackground{

    [self comeToBackgroundMode];

}

- (void)endBackgroundTask

{

    if (self.backgroundTask != UIBackgroundTaskInvalid) {

        [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];

        self.backgroundTask = UIBackgroundTaskInvalid;

    }

    NSLog(@"计数:bgTask 结束了");

}

上一篇下一篇

猜你喜欢

热点阅读