zoukankan      html  css  js  c++  java
  • IOS 后台之长时间任务 beginBackgroundTaskWithExpirationHandler 申请后台十分钟 600秒

    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, 0), ^{
    
     
    
            // 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 4-2 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,    
        0), ^{    
        // 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', 0);
  • 相关阅读:
    PHP 使用 header()实现重定向
    PHP抑制符号 @
    PHP自动加载spl_autoload_register
    打开PHP错误提示
    通过htaccess使用伪静态
    用反引号(``)标注表明或者字段名,防止跟 mysql关键字冲突
    Bootstrap 弹出框(Popover)插件
    jQuery 的 validator 验证,以及添加自定义验证规则。
    线程与并发(一) 多线程基础
    SpringCloud入门
  • 原文地址:https://www.cnblogs.com/cb168/p/5137656.html
Copyright © 2011-2022 走看看