【代码笔记】iOS-获取系统完成任务所需的后台时间
一,代码。
AppDelegate.h

#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; //添加变量
@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundUpdateTask; @end

AppDelegate.m

#import "AppDelegate.h"
#import "RootViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch. RootViewController *rootVC=[[RootViewController alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:rootVC];
self.window.rootViewController=nav; self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
} - (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application
{ [self beingBackgroundUpdateTask];
// 在这里加上你需要长久运行的代码 //最后彻底的还一次。
[self endBackgroundUpdateTask]; } - (void)beingBackgroundUpdateTask
{
self.backgroundUpdateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
//有借有还。
[self endBackgroundUpdateTask];
}];
}
- (void)endBackgroundUpdateTask
{
[[UIApplication sharedApplication] endBackgroundTask: self.backgroundUpdateTask];
self.backgroundUpdateTask = UIBackgroundTaskInvalid;
}

【代码笔记】iOS-获取系统完成任务所需的后台时间的更多相关文章
- IOS 获取系统时间戳
IOS 获取系统时间戳常用方法 通用方法有如下三种: NSLog(); NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:]; NSTimeInte ...
- IOS 获取系统通讯录
进入正题 获取系统通讯录,不想多讲,留下链接http://my.oschina.net/joanfen/blog/140146 通常做法: 首先创建一个ABAddressBookRef类的对象add ...
- iOS 获取系统音量
//设置一个全局变量 UISilder * volumeViewSlider; #pragma mark - 获取系统音量 - (void)configureVolume { volumeView = ...
- ios获取系统时间
//获取系统时间 NSDate * date=[NSDate date]; NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; ...
- iOS 获取系统相册数据(不是调系统的相册)
Framework:AssetsLibrary.framework 主要目的是获取到系统相册的数据,并把系统相册里的照片显示出来. 1.创建一个新的项目: 2.将AssetsLibrary.frame ...
- IOS获取系统时间 NSDate
//返回当前时间,精确到毫秒.- (NSString *)getTimeNow { NSString* date; NSDateFormatter * formatter = [[NSDateForm ...
- IOS 获取系统相册和拍照使用HXPhotoPicker 返回页面时页面上移被nav遮住问题
解决: - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.automaticallyAdj ...
- IOS 获取系统通讯录中的联系人信息
- (IBAction)getAllContactFromSystem { ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, NUL ...
- iOS - 获取系统时间年月日,阳历(公历)日期转农历的方法
//获取当前时间 NSDate *now = [NSDate date]; NSLog(@" now date is: %@ ",now); NSCalendar *calenda ...
随机推荐
- Ruby之基础介绍(二)
前言 上一篇我们简单介绍了下Ruby,这一节我们开始正式步入Ruby的世界,一探究竟. Ruby特点 (1)面向对象支持. (2)动态语言:我们可以修改已经定义过的类,也可以为现有类添加实例方法. ( ...
- 关于SubSonic3.0生成的表名自动加复数(s)的“用户代码未处理SqlException,对象名'xxxs'无效”异常处理
使用SubSonic3.0模版生成时,同2.2版本一样,都会自动在一些类似数据库要用到的关键后面加要s(复数),这里也是3.0的一个小Bug,在查询时由于插件并没有完全的去掉s,所以会产生“用户代码未 ...
- ASP.NET Web API 创建帮助页
1. 安装 Microsoft.AspNet.WebApi.HelpPage 程序包 Install-Package Microsoft.AspNet.WebApi.HelpPage 2. 注册 Ar ...
- 小菜学习Winform(七)系统托盘
前言 有些程序在关闭或最小化的时候会隐藏在系统托盘中,双击或右击会重新显示,winform实现其功能很简单,这边就简单的介绍下. 实现 在winform实现托盘使用notifyIcon控件,如果加菜单 ...
- C/C++ 双精度double 数据相加出错缺陷解释
不知道有没有人和我一样遇到过这样一个问题,请看下面代码. #include<iostream> using namespace std; int main(){ double a=2.3, ...
- SharePoint Server 2013 让上传文件更精彩
新版的SharePoint 2013 提供了多种上传与新建文件的方式,对于与系统集成紧密的IE来上传文档更加方便 使用IE开启SharePoint地址 Figure 1打开文档库,在"新颖快 ...
- JavaWeb:EL表达式
JavaWeb:EL表达式 说明 1.Expression Language语言,一种用于JSP文件中的数据访问的语言. 2.能够简化JSP文件中该数据访问的代码,可用来替代传统的基于<%= % ...
- 相克军_Oracle体系_随堂笔记007-PGA
实际工作中,Oracle中有两个很重要:Server Process 和 PGA. PGA内存作用和构成 1.PGA作用 2.PGA构成 1)private SQL area 2)Sess ...
- (十五)WebGIS中平移功能的设计和实现
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.前言 这一章我们将详细讲解WebGIS工具栏中另一个基础工具——平 ...
- 从View向Controller传递复杂类型Json
mvc给我们提供多种controller中读取view数据的方法 1.从Ruquest["name"]中直接读取 2.将表单中name名称直接写在Action的参数列表中 3.将表 ...