在应用程序使用期间,当连接发生变化时,我需要得到通知。我已经将Reacability.h .m文件导入到我的Swift项目中,并通过添加#include "Reachability.h"来连接它。
在苹果的Reachability示例中,项目设置了一个观察者,以便在连接性发生变化时得到通知。我怎样才能在Swift里设置它呢?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];Swift中没有同等的观察者。斯威夫特拥有像willSet和didSet这样的财产观察者。
发布于 2015-04-08 08:44:51
请参考以下链接,以获得快速https://github.com/ashleymills/Reachability.swift中的可实现性
对于添加的观察者,请像这样使用它
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:", name: ReachabilityChangedNotification, object: reachability)https://stackoverflow.com/questions/29509649
复制相似问题