zoukankan      html  css  js  c++  java
  • iOS 程序退出之后

    转自:http://blog.csdn.net/iitvip/article/details/17356299

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
    __block UIBackgroundTaskIdentifier background_task;
    //注册一个后台任务,告诉系统我们需要向系统借一些事件
    background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
    
    //不管有没有完成,结束background_task任务
    [application endBackgroundTask: background_task];
    background_task = UIBackgroundTaskInvalid;
    }];
    
    /*
    尽量用异步,如果像这样 你会发现主线程会被阻塞
    while(TRUE)
    {
    NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
    [NSThread sleepForTimeInterval:1]; //wait for 1 sec
    }
    */
    //异步
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
    //### background task starts
    NSLog(@"Running in the background\n");
    
    static int i = 0;
    while(i < 5)
    {
    NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
    [NSThread sleepForTimeInterval:1]; //wait for 1 sec
    i++;
    }
    /*
    while(TRUE)
    {
    NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
    [NSThread sleepForTimeInterval:1]; //wait for 1 sec
    i++;
    }
    */
    
    //我们自己完成任务后,结束background_task任务
    //如果我们用while(TRUE)的话,下面这两行代码应该不会执行
    [application endBackgroundTask: background_task];
    background_task = UIBackgroundTaskInvalid;
    });
    }
  • 相关阅读:
    selenium登录百度
    selenium登录实验楼
    selenium登录慕课网
    selenium登录4399
    Python中的inf与nan
    Python—推导式
    vacode 精选插件(只为更舒心的编程)
    PHPStudy_pro 根目录下访问查看目录文件
    Thinkphp5 auto权限
    ThinkPHP admin.php后台登录
  • 原文地址:https://www.cnblogs.com/bluen/p/3593769.html
Copyright © 2011-2022 走看看