文件名称:io后台运行demo
文件大小:3KB
文件格式:M
更新时间:2018-07-16 05:35:27
后台,运行
-(id) init { self = [super init]; if(self) { bgTask = UIBackgroundTaskInvalid; expirationHandler =nil; timer =nil; } return self; } -(void) startBackgroundTasks:(NSInteger)time_ target:(id)target_ selector:(SEL)selector_ { timerInterval =time_; target = target_; selector = selector_; [self initBackgroudTask]; //minimum 600 sec [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self initBackgroudTask]; }]; } -(void) initBackgroudTask { dispatch_async(dispatch_get_main_queue(), ^(void) { if([self running]) [self stopAudio]; while([self running]) { [NSThread sleepForTimeInterval:10]; //wait for finish } [self playAudio]; }); }