[英]How to use Reachability Objective-C class in Swift
在应用使用过程中连接性发生变化时,我需要得到通知。 我已经将Reachability.h .m文件导入到我的Swift项目中,并通过添加#include "Reachability.h"
桥接。
在Apple的Reachability示例项目中 ,设置了观察者以在连接更改时得到通知。 如何在Swift中进行设置?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
Swift中没有等效的观察者。 Swift具有诸如willSet
和didSet
类的属性观察didSet
。
请快速链接以下链接以获取可达性https://github.com/ashleymills/Reachability.swift
对于您的添加观察者,请像这样使用
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:", name: ReachabilityChangedNotification, object: reachability)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.