2014-07-23 4 views

답변

16

UIApplicationWillEnterForegroundNotification을 사용해 보셨습니까?

응용 프로그램은 관심있는 객체에게 전환에 응답 할 기회를주기 위해 applicationWillEnterForeground:을 호출하기 직전에 UIApplicationWillEnterForegroundNotification 알림을 게시합니다.

통지 구독하기 :

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(yourUpdateMethodGoesHere:) 
              name:UIApplicationWillEnterForegroundNotification 
              object:nil]; 

코드를 구현, 그 필요가 호출 될 :

- (void) yourUpdateMethodGoesHere:(NSNotification *) note { 
// code 
} 

탈퇴하는 것을 잊지 마십시오

[[NSNotificationCenter defaultCenter] removeObserver:self]; 
+0

당신이 코드 스피의 조각을 보낼 수 있습니다 사용할 수는 – user3115014

+0

확인 혼동이 하나 http://stackoverflow.com/questions/2191594/send-and-receive-messages-through- nsnotificationcenter-in-objective-c –

7

스위프트 3 버전을

,210
override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    NotificationCenter.default.addObserver(self, 
              selector:#selector(applicationWillEnterForeground(_:)), 
              name:NSNotification.Name.UIApplicationWillEnterForeground, 
              object: nil) 
} 

override func viewWillDisappear(_ animated: Bool) { 
    super.viewWillDisappear(animated) 
    NotificationCenter.default.removeObserver(self) 
} 

func applicationWillEnterForeground(_ notification: NSNotification) { 
    .... 
} 

당신은 또한 NSNotification.Name.UIApplicationDidBecomeActive

관련 문제