我将可达性代码整合到我的应用程序中,并且已成功运行了几个月,但目前为止,我只在iOS 5设备上使用它。 但是它不适用于iOS 4设备。可达性更改通知适用于iOS5,但不适用于iOS4
该通知登记如下:
- (id) init
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChange:)
name:kReachabilityChangedNotification
object:nil];
...
- (void) appBecameActive
{
...
self.reachability = [Reachability reachabilityWithHostName:[url host]];
...
[self.reachability startNotifier];
stopNotifier只获取调用的dealloc中
问题是ReachabilityCallback没有接到回访电话时,有一个reachabiity的变化,但我看不到任何理由为什么它应该可以在iOS5上使用,但不能在iOS4上使用。
的这部分代码是从苹果的示例源代码不变:
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info) {
#pragma unused (target, flags)
NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback");
NSCAssert([(__bridge id)info isKindOfClass:[Reachability class]], @"info was wrong class in ReachabilityCallback");
Reachability *noteObject = (__bridge Reachability *)info;
// Post a notification to notify the client that the network reachability changed.
[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:noteObject];
}
如前所述,一切都已经很长一段时间对iOS5的设备上运行时工作正常,有其他人遇到过类似的问题过去将可达性代码整合到iOS4中?
每次我与可达性工作,我链接SystemConfiguration框架,你在干什么呢? – kevboh
谢谢,但正如我所说,它可以在iO5上运行,如果没有框架,它将无法运行。 – Gruntcakes
... [你刚刚对你的问题做了什么?](http://stackoverflow.com/posts/10921145/revisions) – BoltClock