This maintenance update for DTFoundation fixes a few minor issues and adds a new custom-colored disclosure indicator.
Changes
- ADDED: [DTCustomColoredAccessory] Added left arrow disclosure indicator
- ADDED: [DTReachability] Demo App
- CHANGED: [DTReachability] to observe reachability to apple.com instead of general IP connectivity as this addresses some issues where DNS resolving might lag behind
- FIXED: [DTSidePanel] Appearance Notifications not sent to replaced panels
Thanks to Carl Kabbe for contributing the left arrow disclosure indicator for DTCustomColoredAccessory. I have no idea for which scenario you might need that, but now we have all 4 directions.
The DTSidePanel Appearance notification fix is dedicated to René Pirringer who is using this component in a commercial app. Thus he’s rigorously testing it and found that when programmatically changing the center panel it wouldn’t get the proper notifications.
Appearance Notifications
A view controller which appears should always get these notifications, in this order:
- willMoveToParentViewController:
- viewWillAppear:
- viewDidAppear:
- didMoveToParentViewController:
The same order is true for disappearing, but there the new parent view controller will be nil. The whole thing gets slightly more confusing if you are embedding a view controller inside a UINavigationController since this sends the willMove right away, but the other 3 notifications only when the navigation controller actually appears on screen.
Reachability: Name vs. IP
A user of AutoIngest for Mac reported that he would be getting error messages from the synchronizing right after waking up his MacBook. Apparently on some Macs there is a time interval between TCP/IP connectivity being established and when DNS names can be resolved. Thanks to Nick Lockwood (who made FXReachability, where I gleaned this better method) I was able to figure out a better method for Reachability.
Consider the before/after:
// BEFORE - thanks Erica Sadun BOOL ignoresAdHocWiFi = NO; struct sockaddr_in ipAddress; bzero(&ipAddress, sizeof(ipAddress)); ipAddress.sin_len = sizeof(ipAddress); ipAddress.sin_family = AF_INET; ipAddress.sin_addr.s_addr = htonl(ignoresAdHocWiFi ? INADDR_ANY : IN_LINKLOCALNETNUM); /* Can also create zero addy struct sockaddr_in zeroAddress; bzero(&zeroAddress, sizeof(zeroAddress)); zeroAddress.sin_len = sizeof(zeroAddress); zeroAddress.sin_family = AF_INET; */ _reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (struct sockaddr *)&ipAddress); // AFTER - thanks Nick Lockwood _reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "apple.com"); |
Not only is the whole creation of the reachability observer much more compact, it also solves the DNS lag problem. I have to admit, that I didn’t actually test for differences, but I trust Nick.
To simplify use even further I added a macro for determining the internet connectivity status from the SCNetworkConnectionFlags:
// macro to determine reachability status from connection flags #define DTReachabilityIsReachableFromFlags(connectionFlags) ((connectionFlags & kSCNetworkFlagsReachable) && !(connectionFlags & kSCNetworkFlagsConnectionRequired)) |
With this macro the demo app’s View Controller becomes very simple:
@implementation ViewController { id _observer; // reference for reachability observer } - (void)viewDidLoad { [super viewDidLoad]; // register a reachability observer __weak ViewController *weakself = self; _observer = [DTReachability addReachabilityObserverWithBlock:^(SCNetworkConnectionFlags connectionFlags) { // update label based on connection flags if (DTReachabilityIsReachableFromFlags(connectionFlags)) { weakself.label.text = @"Reachable"; weakself.label.textColor = [UIColor greenColor]; } else { weakself.label.text = @"Not Reachable"; weakself.label.textColor = [UIColor redColor]; } }]; } - (void)dealloc { [DTReachability removeReachabilityObserver:_observer]; _observer = nil; } @end |
As usual the update is available direct from the GitHub repository or via CocoaPods.
Categories: Updates