var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let checkNetworkReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)).takeRetainedValue()
}
var flags: SCNetworkReachabilityFlags = 0
if SCNetworkReachabilityGetFlags(checkNetworkReachability, &flags) == 0 {
println("您的设备不能链接网络");
return;
}
//var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil);
if SCNetworkReachabilitySetCallback(checkNetworkReachability, ????????, nil) != 0{//&context
println("设置回调成功");
if SCNetworkReachabilityScheduleWithRunLoop(checkNetworkReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode) != 0
{
println("设置runloop成功")
}
}
图中????????处应该怎么设置
参数是一个SCNetworkReachabilityCallBack类型的东东,
/*!
@typedef SCNetworkReachabilityCallBack
@discussion Type of the callback function used when the
reachability of a network address or name changes.
@param target The SCNetworkReachability reference being monitored
for changes.
@param flags The new SCNetworkReachabilityFlags representing the
reachability status of the network address/name.
@param info A C pointer to a user-specified block of data.
*/
typealias SCNetworkReachabilityCallBack = CFunctionPointer<((SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer<Void>) -> Void)>
这是不是就是一个函数指针?
var callback = SCNetworkReachabilityCallBack?;
我要怎么定义一个函数,让这个函数指针指向函数呢?
![](http://imgsrc.baidu.com/forum/w%3D580/sign=3814ca05aa014c08193b28ad3a7a025b/78689445d688d43f56a4d65e7e1ed21b0ff43bfc.jpg)
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let checkNetworkReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)).takeRetainedValue()
}
var flags: SCNetworkReachabilityFlags = 0
if SCNetworkReachabilityGetFlags(checkNetworkReachability, &flags) == 0 {
println("您的设备不能链接网络");
return;
}
//var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil);
if SCNetworkReachabilitySetCallback(checkNetworkReachability, ????????, nil) != 0{//&context
println("设置回调成功");
if SCNetworkReachabilityScheduleWithRunLoop(checkNetworkReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode) != 0
{
println("设置runloop成功")
}
}
图中????????处应该怎么设置
参数是一个SCNetworkReachabilityCallBack类型的东东,
/*!
@typedef SCNetworkReachabilityCallBack
@discussion Type of the callback function used when the
reachability of a network address or name changes.
@param target The SCNetworkReachability reference being monitored
for changes.
@param flags The new SCNetworkReachabilityFlags representing the
reachability status of the network address/name.
@param info A C pointer to a user-specified block of data.
*/
typealias SCNetworkReachabilityCallBack = CFunctionPointer<((SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer<Void>) -> Void)>
这是不是就是一个函数指针?
var callback = SCNetworkReachabilityCallBack?;
我要怎么定义一个函数,让这个函数指针指向函数呢?
![](http://imgsrc.baidu.com/forum/w%3D580/sign=3814ca05aa014c08193b28ad3a7a025b/78689445d688d43f56a4d65e7e1ed21b0ff43bfc.jpg)