【代码笔记】iOS-获取系统完成任务所需的后台时间
来源:互联网 发布:淘宝收货地址写什么 编辑:程序博客网 时间:2024/06/05 10:42
一,代码。
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;}
0 0
- 【代码笔记】iOS-获取系统完成任务所需的后台时间
- iOS 进入后台后再向系统借一点时间完成任务
- C/c++获取运行代码的所需的时间
- 【代码笔记】iOS-获取现在的日历时间
- IOS 获取系统的时间
- 获取系统时间代码
- VC++ 获取系统时间与计算某段代码所消耗时间(毫秒级)
- ios获取系统时间
- 获取系统时间ios
- ios获取系统时间
- iOS获取系统时间
- iOS 获取系统时间
- IOS 获取系统时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- Tomcat集群部署
- NPOI读写Excel
- Windows D3D Intro - On Device Lost
- 2016.03.30 Supervised learning
- FZU-2148-Moon Game,,几何计算~~
- 【代码笔记】iOS-获取系统完成任务所需的后台时间
- Linux系统查看和转化文件编码
- Cordova开发平台配置--Android
- ASP web.config 配置遇到的问题
- 公司(视频 社交)项目分享
- Android视频的全屏切换
- 《iOS Human Interface Guidelines》——Segmented Control
- 1.6算法入门之牛顿迭代式求方程根
- Java中要注意的几个问题