我有时需要检查互联网连接并使用" Reachability"为了这个目的。
最好使用" Reachability"手动检查互联网连接。像:
BOOL status = ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] != NotReachable);
或使用可达性通知和
//Start listening for reachability notifications on the current run loop
- (BOOL) startNotifier;
通知是否需要一些手机资源,如电池等,如果我不使用" stopNotifier"我会遇到一些问题?
由于
答案 0 :(得分:1)
IMO - 使用通知是可行的方法。 Reachability类可以很好地用最少的资源跟踪连接。如果您必须具有连接以执行某些操作,请使用通知。另一个好处是您可以使用通知执行其他操作(在本地保存数据,通知用户等)。当您不再关心连接时,您可能希望使用stopNotifier。
答案 1 :(得分:1)
这很简单: