1
앱이 백그라운드에서 3 분 이상 계속 남아있을 때 스플래시 화면을 표시하려고합니다. 백그라운드 타이머를 시작하여 UI 업데이트를 처리 할 함수를 트리거했습니다. 타이머가 난 그래서 그것은 시작 화면입니다처럼 보이게 창에 이미지를 추가 내 UI의 즉를 업데이트하는 함수를 호출 호출 이제앱이 배경에있을 때 백그라운드 스레드에서 UI를 업데이트하여 다음 재개시 스플래시 화면을 표시합니다.
- (void)applicationDidEnterBackground:(UIApplication *)
if (application.applicationState == UIApplicationStateBackground) {
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
//and create new timer with async call:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
splashTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timerFired) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:splashTimer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
});
}
}
. 난 배경 스레드에서 호출 할 때 응용 프로그램 전경 다시
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if ([[self.window subviews] count] > 1) {
[NSThread sleepForTimeInterval:1.0];
[[[self.window subviews] lastObject] removeFromSuperview];
}
}
를 입력하지만 내 시작 화면이 표시되지 않을 때
- (void)timerFired
{
[splashTimer invalidate];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Splash_Screen.png"]];
splash.frame = self.window.bounds;
[self.window addSubview:splash];
}];
}
다음 창에서이 이미지를 제거합니다. 나는 운을 제외한 모든 것을 시도했다. 내 문제는 배경 타이머에서 내 타이머가 호출되고이 스레드의 이미지를 추가하려는 경우 UI가 업데이트되지 않는다는 것입니다. 어떤 도움?