当网络状态改变时,需要通知我。我已经找到了如何在其他专题中检查网络可达性。
有什么代表我可以用吗?
发布于 2014-11-20 16:58:58
假设您正在使用来自苹果的可实现性示例项目的代码,您将希望为kReachabilityChangedNotification通知注册。
假设您有一个具有以下方法的UIViewController子类:
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()方法中注册该通知,如下所示:
let nc = NSNotificationCenter.defaultCenter();
nc.addObserver(self, selector:"handleReachabilityChanged:", name:kReachabilityChangedNotification, object:nil);有关如何设置和删除通知处理程序的方法,请参阅NSNotificationCenter和NSNotification文档。
https://stackoverflow.com/questions/27044690
复制相似问题