0
我用下面的代碼我怎麼能自動停止,當應用程序在前臺狀態即將所有後臺任務
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
if ([[UIApplication sharedApplication]
respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)])
{
UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{}];
// Perform work that should be allowed to continue in background
[self changeCounter];
//[NSThread detachNewThreadSelector:@selector(changeCounter) toTarget:self withObject:_viewController];
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}
#endif
changeCounter包含了一段時間後。但如果應用進來前景停止循環之前可能最後一圈那麼我只能看到黑色屏幕直到循環完成。 所以,我怎麼能停止所有任務的應用程序自帶的前景
這是changeCounter
-(void)changeCounter{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
while(back==1.0f){
NSLog(@"loop is runnig");
[NSThread sleepForTimeInterval:1.0];
if(_viewController.minutes<0){
if(_viewController.fadeSeconds>0){
float div=_viewController.deviceVolume/[_viewController.volumeData.fadeTime floatValue];
_viewController.musicPlayer.volume=_viewController.musicPlayer.volume-div;
_viewController.fadeSeconds-=1;
}
else {
[self stop];
//self.musicPlayer.volume=0.0f;
// counter=0;
NSLog(@"closing the sound");
[_viewController.musicPlayer pause];
NSLog(@"fade seconds %i minutes ",_viewController.fadeSeconds);
if(_viewController.dvol==0){
_viewController.musicPlayer.volume=deviceVolume;
_viewController.dvol=1;
}
back=0.0f;
}// end of the else
}
是我想殺了它,因爲當應用程序將變爲活動時,另一個任務將用gui執行 –
發佈代碼[self changeCounter] – jaminguy
請檢查編輯 –