2014-11-20 3 views

답변

1

Apple's Reachability sample project의 코드를 사용한다고 가정하면 kReachabilityChangedNotification 알림에 등록하려고합니다.

let nc = NSNotificationCenter.defaultCenter(); 
nc.addObserver(self, selector:"handleReachabilityChanged:", name:kReachabilityChangedNotification, object:nil); 

NSNotificationCenter를 참조하십시오

func handleReachabilityChanged(notification:NSNotification) 
{ 
    // notification.object will be a 'Reachability' object that you can query 
    // for the network status. 

    NSLog("Network reachability has changed."); 
} 

그런 다음이 같이 당신의 UIViewController의 viewDidLoad() 방법에 그 통지를 등록 할 수 있습니다 :

당신이 방법이있는 UIViewController 하위를 가정 알림 처리기를 설정하고 해체하는 방법은 NSNotification 설명서를 참조하십시오.