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. C语言变量、函数的作用域及变量的存储方式

    一.变量的作用域和存储方式 在C语言中每个变量都有两种基本属性:数据类型.数据的存储类别. 数据类型很多人都已熟知,例如:字符型(char).整型(int).浮点型(float)等等.存储类别是指数据 ...

  2. xcopy 提示文件 还是目录

    xcopy /y a.jpg .\pics\b.jpg很多次,但xcopy总是问我“文件名还是目录名”gg了一下,发现答案可以这样通过管道来做echo f | xcopy /y a.jpg .\pic ...

  3. BZOJ4689 Find the Outlier 【高斯消元】*

    BZOJ4689 Find the Outlier Description Abacus教授刚刚完成了一个制作数表的计算引擎的设计.它被设计用于同时计算一个多项式在许多点的取值.例如对于多项式 f(x ...

  4. 开始学习jQuery

    一 jQuery是什么? 1. jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. 2.jQuery是继prototype之后又一个 ...

  5. Android学习路线总结,绝对干货(转)

    title: Android学习路线总结,绝对干货tags: Android学习路线,Android学习资料,怎么学习androidgrammar_cjkRuby: true--- 一.前言 不知不觉 ...

  6. c# String.Split数组省去空字符

    public static void test() { string txt = "hi[#b1.jpg][#b4.jpg]few[#b1-3.jpg]"; txt = " ...

  7. js验证手机号码,邮箱,qq号

    function validateMail(str:String) { var re_m = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2} ...

  8. js各种效果

    1.JavaScript 仿LightBox内容显示效果 2.固定高度的div,竖直方向出现滚动条,水平方向固定 http://www.jb51.net/css/109928.html <!do ...

  9. JVM内存管理之杂谈(借此也论一论obj=null)

    作为一个程序猿,修炼的过程就犹如玄幻小说中的主角,不仅需要练习各种武技,内气的修炼的一样重要.虽然武技可以迅速的提升主角的实力,但是在内气太差的情况下,根本发挥不出武技的十之一二. 因此,在介绍过设计 ...

  10. java代码=====实现修改while()

    总结: package com.mmm; public class cse { public static void main(String[] args) { // int count=0;你妹,我 ...