10分钟

beginBackgroundTaskWithExpirationHandler,beginBackgroundTaskWithName

endBackgroundTask

定义变量

UIBackgroundTaskIdentifier bgTask;

- (void)applicationDidEnterBackground:(UIApplication *)application

{

    bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{

        // Clean up any unfinished task business by marking where you

        // stopped or ending the task outright.

        [application endBackgroundTask:bgTask];

        bgTask = UIBackgroundTaskInvalid;

    }];

    // Start the long-running task and return immediately.

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ), ^{

        // Do the work associated with the task, preferably in chunks.

        [application endBackgroundTask:bgTask];

        bgTask = UIBackgroundTaskInvalid;

    });

}

Declaration

Swift

func beginBackgroundTaskWithExpirationHandler(_ handler: (() -> Void)?) -> UIBackgroundTaskIdentifier

Objective-C

- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler

    Listing - Starting a background task at quit time
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
), ^{
// Do the work associated with the task.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}

^{} block 语法。

dispatch_queue_create

dispatch_release

dispatch_async_f

Queue: dispatch_queue_t;

Queue := dispatch_queue_create('Video Capture Queue', );

最新文章

  1. os模块汇总
  2. Spring Boot 1 创建Demo
  3. c语言知识(2)
  4. linux 交换分区分配规则
  5. Hibernate事务传播性
  6. 代码生成引擎之T4模版
  7. final, finally, finalize 的区别
  8. DL4NLP——词表示模型(三)word2vec(CBOW/Skip-gram)的加速:Hierarchical Softmax与Negative Sampling
  9. TestNG的简单使用
  10. java基础笔记(4)----数组
  11. python实现购物车
  12. html5配合css3实现带提示文字的输入框(摆脱js)
  13. python importlib动态导入模块
  14. Java进阶篇之十五 ----- JDK1.8的Lambda、Stream和日期的使用详解(很详细)
  15. [2019.03.16]使用DOM操作函数和CSS选择器来针对已有的HTML进行只凭JS的改动
  16. Tomcat zabbix监控、jmx监控、zabbix_java_gateway
  17. Ionic开发遇到的坑整理
  18. DOM元素加载之前执行的jQuery代码
  19. spring task 实现定时执行(补充:解决定时任务执行2次问题)
  20. ISCC2018(misc)

热门文章

  1. OC中使用单例模式
  2. js实现图片上传
  3. BZOJ2687 交与并/BZOJ2369 区间【决策单调性优化DP】【分治】
  4. POJ3422 Kaka's Matrix Travels 【费用流】*
  5. 迫不及待地体验了一把 C#8.0 中的可空引用类型(Nullable Reference)
  6. ruby 的数组操作
  7. hadoop2.x常用端口、定义方法及默认端口、hadoop1.X端口对比
  8. CCF 集合竞价
  9. Ubuntu下环境变量设置
  10. CentOS解压rar文件