Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3315 from SlaunchaMan/fix-reachability-warnings
Browse files Browse the repository at this point in the history
Fixed static analyzer warnings on AFNetworkReachabilityManager
  • Loading branch information
kcharwood committed Jan 28, 2016
2 parents 0574a40 + 8627ada commit c7f8d01
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions AFNetworking/AFNetworkReachabilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
}

@interface AFNetworkReachabilityManager ()
@property (readwrite, nonatomic, strong) id networkReachability;
@property (readonly, nonatomic, assign) SCNetworkReachabilityRef networkReachability;
@property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
@property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
@end
Expand All @@ -123,24 +123,24 @@ + (instancetype)sharedManager {
return _sharedManager;
}

#ifndef __clang_analyzer__
+ (instancetype)managerForDomain:(NSString *)domain {
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]);

AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];

CFRelease(reachability);

return manager;
}
#endif

#ifndef __clang_analyzer__
+ (instancetype)managerForAddress:(const void *)address {
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];

CFRelease(reachability);

return manager;
}
#endif

+ (instancetype)manager
{
Expand All @@ -164,7 +164,7 @@ - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability {
return nil;
}

self.networkReachability = CFBridgingRelease(reachability);
_networkReachability = CFRetain(reachability);
self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;

return self;
Expand All @@ -177,6 +177,10 @@ - (instancetype)init NS_UNAVAILABLE

- (void)dealloc {
[self stopMonitoring];

if (_networkReachability != NULL) {
CFRelease(_networkReachability);
}
}

#pragma mark -
Expand Down Expand Up @@ -213,14 +217,13 @@ - (void)startMonitoring {

};

id networkReachability = self.networkReachability;
SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
SCNetworkReachabilitySetCallback((__bridge SCNetworkReachabilityRef)networkReachability, AFNetworkReachabilityCallback, &context);
SCNetworkReachabilityScheduleWithRunLoop((__bridge SCNetworkReachabilityRef)networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{
SCNetworkReachabilityFlags flags;
if (SCNetworkReachabilityGetFlags((__bridge SCNetworkReachabilityRef)networkReachability, &flags)) {
if (SCNetworkReachabilityGetFlags(self.networkReachability, &flags)) {
AFPostReachabilityStatusChange(flags, callback);
}
});
Expand All @@ -231,7 +234,7 @@ - (void)stopMonitoring {
return;
}

SCNetworkReachabilityUnscheduleFromRunLoop((__bridge SCNetworkReachabilityRef)self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
}

#pragma mark -
Expand Down

0 comments on commit c7f8d01

Please sign in to comment.