iOS适配IPV6,AFNetworking的修改

需要修改的文件

  • AFNetworkReachabilityManager.h


    01.jpg
// 修改之前
+ (instancetype)managerForAddress:(const void *)address;
// 修改之后
+ (instancetype)managerForAddress:(const struct sockaddr_in6 *)address;
  • AFNetworkReachabilityManager.m


    02.jpg
// 修改之前
+ (instancetype)sharedManager {
    static AFNetworkReachabilityManager *_sharedManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedManager = [self manager];
    });

    return _sharedManager;
}
// 修改之后
+ (instancetype)sharedManager {
    static AFNetworkReachabilityManager *_sharedManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        struct sockaddr_in6 address;
        bzero(&address, sizeof(address));
        address.sin6_len = sizeof(address);
        address.sin6_family = AF_INET6;
        _sharedManager = [self managerForAddress:&address];
    });
    
    return _sharedManager;
}
03.jpg
// 修改之前
+ (instancetype)managerForAddress:(const void *)address {
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
    AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];

    CFRelease(reachability);

    return manager;
}
// 修改之后
+ (instancetype)managerForAddress:(const struct sockaddr_in6 *)address {
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
    AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
    
    CFRelease(reachability);
    
    return manager;
}

你可能感兴趣的:(iOS适配IPV6,AFNetworking的修改)