美文网首页
IOS 无限后台

IOS 无限后台

作者: Miro丶K | 来源:发表于2016-11-14 09:58 被阅读0次

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

if (self.background_task == UIBackgroundTaskInvalid) {

self.background_task = [application beginBackgroundTaskWithExpirationHandler:nil];

__weak __typeof(&*self)weakSelf = self;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

while(1) {

if (!weakSelf.backgroundActive) {

[application endBackgroundTask:weakSelf.background_task];

weakSelf.background_task = UIBackgroundTaskInvalid;

break;

}

//编写执行任务代码

NSLog(@"%@", [NSDate date]);

sleep(1);

}

});

}

}

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

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

self.backgroundActive = YES;

[self applicationBackgrountHandler:application];

}

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

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

self.backgroundActive = NO;

}

相关文章

  • IOS 无限后台

    - (void)applicationBackgrountHandler:(UIApplication *)app...

  • iOS-无限时后台

    创建一个计时器放到NSRunLoop中 修改 UIBackgroundTaskIdentifier状态

  • iOS后台无限发送请求

    根据苹果文档中关于后台执行的描述,任何app都有10分钟左右的后台任务执行时间。 10分钟后,app会被iOS强行...

  • iOS开发之无限后台

    Swift实现(在AppDelegate对应的方法中添加如下代码) funcapplicationDidEnter...

  • IOS 无限后台运行方法

    先介绍一篇关于后台运行的文章:http://www.jianshu.com/p/174fd2673897 此篇文章...

  • iOS--无限后台定位

    科普: 实际上APP拥有四种后台模式,无论是哪一种后台机制,均需要利用苹果给予的相应后台接口实现。IOS7系统中,...

  • iOS无限后台加速耗电的问题

    赶时间的只要看这里 把应用的『定位服务』关掉,既可! 背景 总所周知,iPhone的电池容量本身比较小。所以iOS...

  • 关于iOS APP后台无限存活问题

    由于产品需求需要APP退回到后台后,还要存活,不能被挂起杀掉。虽然这个实在有违苹果的设计宗旨,而且耗电。(难道苹果...

  • iOS实现无限后台background的方法

    本文csdn地址:http://blog.csdn.net/game3108/article/details/51...

  • Paper Collection - Background Ta

    1.IOS后台运行机制详解(一)2.IOS后台运行机制详解(二)3.IOS后台运行 之 后台播放音乐4.转载:IO...

网友评论

      本文标题:IOS 无限后台

      本文链接:https://www.haomeiwen.com/subject/cckcuttx.html