2017-02-10 4 views
0

내 UI는 UILabel의 애니메이션을 사용하여 특정 상태를 나타냅니다. NSUserDefaults standardUserDefaults에서 키를 사용하여 해당 상태를 켜고 끕니다. 홈 버튼을 시뮬레이션 한 다음 앱을 클릭 한 후 앱이 활성화되면 애니메이션이 올바르게 다시 시작됩니다 (시뮬레이터에서). 그러나 잠금 단추를 시뮬레이션 한 다음 홈을 클릭하면 올바르게 다시 시작되지 않습니다. 두 이벤트 모두 콘솔에 표시되며 두 경우 모두 - (void) startFlashingButton 메서드가 호출됩니다. 나는 그것이 왜 한 경우에는 효과가 있고 다른면에는 효과가 있는지 알 수 없다. 나는 어떤 도움을 주셔서 감사합니다.ios 애니메이션이 다시 시작되지 않습니다.

편집 2/14/17 : 나는 UINotification과 관련된 다른 게시판에서 여러 게시물을 읽었습니다. 분명히 일하기가 매우 어렵습니다. 앱 대행자에게 알림이 전송되면 애니메이션이 실행됩니다. 특정 시간에 알림을 사용하지 않도록하는 일종의 '방해 금지'시스템을 설정하고자했습니다. 내 이해 UINotification에 의해 자동화되지 않을 수 있습니다 그것은 전면 및 센터 또는 백그라운드에서 및 작업 단추 중 하나에 사용자 도청 않으면 알림을 볼 수 없기 때문에. 앱이 백그라운드에 있고 사용자가 알림을 무시하면 앱이 실행되지 않으므로 시간에 방해가되는지 여부를 알 수 없습니다. 또한 앱이 일시 중지되었을 때 타이머가 인식되지 않기 때문에 NSTimer를 사용하여이 작업을 안정적으로 수행 할 수 없습니다. 앱이 백그라운드로 전환 된 직후에 인식됩니다. 간단히 말해서, 시뮬레이션이 실행되지 않는 것보다 훨씬 큰 문제가 있습니다. 하지만 답장을 보내 주신 모든 분들께 감사드립니다. 여기

가 startFlashingButton 방법이다 앱 대리자

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startFlashingButton) name:UIApplicationDidBecomeActiveNotification object:nil]; 

I는 synchonize : -viewDidLoad에서

-(void) startFlashingButton 
{ 
    NSUserDefaults *storage = [NSUserDefaults standardUserDefaults]; 
    if([storage boolForKey:@"animation started"] == YES){ 
    // Fade out the view right away 
    [UIView animateWithDuration:2.0 
          delay: 0.0 
         options: (UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction) 
        animations:^{ 
         self.timerLabel.alpha = 0.0; 
        } 
        completion:^(BOOL finished){ 
         // Wait one second and then fade in the view 
         [UIView animateWithDuration:1.0 
               delay: 2.0 
              options:UIViewAnimationOptionCurveEaseOut 
              animations:^{ 
               self.timerLabel.alpha = 1.0; 
              } 
              completion:nil]; 
        }]; 
    } 
    [storage synchronize]; 
} 

, I는 다음과 같이하여 활성화 될 때 통지를 앱 설정 앱이 백그라운드로 들어가면 다음과 같이 기본값이됩니다.

- (void)applicationDidEnterBackground:(UIApplication *)application { 
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
NSLog(@"application did enter background"); 
NSUserDefaults *storage = [NSUserDefaults standardUserDefaults]; 
[storage synchronize]; 
+0

디버그합시다. 앱이 앞으로 돌아 왔을 때'startFlashingButton'이 호출되고 있습니까? 그렇다면 'animateWithDuration' 부분이 실행됩니까? – matt

+0

'info.plist'에서'Application이 백그라운드에서 실행되지 않습니다'는'NO'로 설정 되었습니까? 또한'applicationDidEnterBackground :'를 디버깅 했습니까? –

+0

예, applicationDidEnterBackground가 호출되었습니다. 아니요, 애플은 백그라운드에서 실행되도록 info.plist가 설정되어 있지 않습니다. Apple은 몇 가지 범주에서만 이것을 허용 할 것이고 내 응용 프로그램은 적용되지 않을 가능성이 있기 때문입니다. –

답변

0

Apple의 문서 사용자가 홈 버튼을 누르면 잠자기/깨우기 버튼을 누르면, 또는 시스템이 다른 응용 프로그램, 배경 상태로 다음 전경 응용 프로그램 비활성 상태로 전환하고를 시작하면 background transition cycle에 tation는

을 말한다. 이러한 전환으로 인해 앱 위임자의 applicationWillResignActive : 및 applicationDidEnterBackground : 메소드가 호출됩니다.

따라서 잠그고 홈 버튼을 누르면 앱이 백그라운드에서 실행 중이지만 사임하지 않을 수 있습니다.

확실히 당신의 앱이 suspended로 이동합니다 다른 NO로 설정하여 info.plistApplication does not run in background 있음을,이 도우미 메서드를 만드는 시도하고 또한 모두 applicationWillResignActive:applicationDidEnterBackground:

-(void)saveUserDefaults { 
    NSLog(@"application did enter background"); 
    NSUserDefaults *storage = [NSUserDefaults standardUserDefaults]; 
    [storage synchronize]; 
} 

에 문의하십시오.

+0

applicationWillResignActive가 호출되고 applicationDidEnterBackground가 호출 될 때이 작업을 수행합니다. 애플은 백그라운드에서 실행되지 않는다. 왜냐하면 애플은 단지 몇 가지 카테고리에 대해서만 이것을 허용하고 나의 애플 리케이션은 아마 그들 중 하나에 없을 것이기 때문이다. –