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', );

IOS 后台之长时间任务 beginBackgroundTaskWithExpirationHandler 申请后台十分钟 600秒的更多相关文章

  1. iOS实现程序长时间未操作退出

    大部分银行客户端都有这样的需求,在用户一定时间内未操作,即认定为token失效,但未操作是任何判定的呢?我的想法是用户未进行任何touch时间,原理就是监听runloop事件.我们需要进行的操作是创建 ...

  2. Android长时间后台运行Service

         项目需要在后台获取GPS经纬度.当用户对手机有一段时间没有操作后,屏幕(Screen)将从高亮(Bright)变为暗淡(Dim),如果再过段时间没操作, 屏幕(Screen)将又由暗淡(Di ...

  3. 如何避免后台IO高负载造成的长时间JVM GC停顿(转)

    译者著:其实本文的中心意思非常简单,没有耐心的读者建议直接拉到最后看结论部分,有兴趣的读者可以详细阅读一下. 原文发表于Linkedin Engineering,作者 Zhenyun Zhuang是L ...

  4. Handler处理长时间事件

    当我们在处理一些比较长时间的事件时候,比如读取网络或者数据库的数据时候,就要用到Handler,有时候为了不影响用户操作应用的流畅还要开多一个线程来区别UI线程,在新的线程里面处理长时间的操作.开发的 ...

  5. 使用joda-time工具类 计算时间相差多少 天,小时,分钟,秒

    下面程序使用了两种方法计算两个时间相差 天,小时,分钟,秒 package jodotest; import java.text.ParseException; import java.text.Si ...

  6. ios之申请后台延时执行和做一个假后台的方法(系统进入长时间后台后,再进入前台部分功能不能实现)

    转自:http://sis hu ok.com/forum/blogCategory/showByCategory.html?categories_id=138&user_id=10385   ...

  7. 实现iOS长时间后台的两种方法:Audiosession和VOIP(转)

    分类: Iphone2013-01-24 14:03 986人阅读 评论(0) 收藏 举报 我们知道iOS开启后台任务后可以获得最多600秒的执行时间,而一些需要在后台下载或者与服务器保持连接的App ...

  8. 实现iOS长时间后台的两种方法:Audiosession和VOIP

    http://www.cocoachina.com/applenews/devnews/2012/1212/5313.html 我们知道iOS开启后台任务后可以获得最多600秒的执行时间,而一些需要在 ...

  9. ios之申请后台延时执行和做一个假后台的方法

    转自:http://sis hu ok.com/forum/blogCategory/showByCategory.html?categories_id=138&user_id=10385   ...

随机推荐

  1. 搭建简单Samba服务器

    本文主要实现搭建简单的Samba服务器,使得Windows能访问Linux下的共享目录,为了简单,已经关闭iptables和selinux. 1.安装samba服务器 #yum list all sa ...

  2. [译]SSL/TLS真的被BEAST攻击攻破了吗?真实情况是怎样的?我应该做什么?

    原文链接:https://luxsci.com/blog/is-ssltls-really-broken-by-the-beast-attack-what-is-the-real-story-what ...

  3. Linux 用C语言实现简单的shell(2)

    不知不觉两周没有发文了,因为“一万美金的福特奖学金答辩”,ACM比赛,网络论文阅读和网络大作业一大堆事把时间冲散了,所以先写一篇博文补上之前一坑. 之前发了一篇关于linux 用C语言实现简单shel ...

  4. NET Core 2.2

    .NET Core 2.2 新增部分功能使用尝鲜 https://www.cnblogs.com/viter/p/10070248.html 前言     美国当地时间12月4日,微软2019开发者大 ...

  5. 在iOS中使用ZBar扫描二维码

    最近在做的项目中需要用到二维码扫描功能,之前在Android中使用过ZXing识别二维码,ZXing也有对应的iOS版本,经过了解,ZBar也是一个常用的二维码识别软件,并分别提供了iOS和Andro ...

  6. matlab 中的function定义. 用最简单的例子说明.

    function y=myfunction(a,b)其中a,b是输入函数的参数,y是函数返回的值.当需要返回多个值时,可以将y看作一个数组,或者直接将函数的开头写成如function [x,y]=my ...

  7. grpc xservice 使用

    1. 安装(此处比较简单) dep 包管理 配置环境变量 GOPATH/bin GO/bin protoc 下载并配置环境变量 2. xservice 安装 a. 预备(一些需要的依赖) mkdir ...

  8. Automating CSS Regression Testing

    The following is a guest post by Garris Shipon . We've touched on the four types of CSS testing here ...

  9. 在一个form中有两个submit,值分别为修改和删除,如何在提交时用js判断submit值为修改还是删除呢

    同一个form里,不管哪个 submit 都是直接提交form表单里的内容. 要达到你的目的,就不能用类型为 submit 的按钮,要用 button,然后加onclick 方法来自定义预处理参数,然 ...

  10. 修改 CentOS 中的 repo

    修改 CentOS 中的 repo 原因 由于安装 odoo 10 太慢,因为服务器是国外的. 修改 进入 repo 文件夹 cd /etc/yum.repos.d/ ls 可以看到所有的源.