| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
iosbg
10年前发布

iOS使后台可以运行代码 比如定时器

//后台运行定时器    -(void)applicationDidEnterBackground:(UIApplication *)application{        UIApplication*   app = [UIApplication sharedApplication];        __block  UIBackgroundTaskIdentifier bgTask;        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{            dispatch_async(dispatch_get_main_queue(), ^{                if (bgTask != UIBackgroundTaskInvalid)                {                    bgTask = UIBackgroundTaskInvalid;                }            });        }];        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{            dispatch_async(dispatch_get_main_queue(), ^{                if (bgTask != UIBackgroundTaskInvalid)                {                    bgTask = UIBackgroundTaskInvalid;                }            });        });