1

After upgrading to iOS 9. My app is having a strange problem.

PROBLEM : Whenever the network reachability changes, The app's view freezes. It is not responding to any touch events. It has not crashed either . I checked the logs. The only change was network reachability.

MORE INFORMATION:

1) If you quit the app and open again with Internet online, it's working fine.

2) If I open the app with Internet offline, the view freezes. This doesn't happen in iOS 8.4.

I'm using Reachability by Tony million library for checking the online/offline status.

Has anyone faced the same issue after upgrading to iOS 9?

Code for reference:

self.appIsOnline = YES;
_reachability = [Reachability reachabilityWithHostName:@"www.google.com"];

__weak __typeof(self)weakSelf = self;
[_reachability setReachableBlock: ^(Reachability * reachability) {

    NSLog(@"Online");

    if (!weakSelf.appIsOnline)
    {
        weakSelf.appIsOnline = YES;
        weakSelf.willShowAlertView = YES;
        dispatch_async(dispatch_get_main_queue(), ^{
            CustomAlertView *alertView = [[CustomAlertView alloc] initWithTitle:@"Warning" andMessage:@"The internet connection appears to be online. The app will switch to online mode now" delegate:weakSelf withButtons:@[@"OK"]];
            alertView.shouldTapOutsideToClose = YES;
            [alertView showInView:MAIN_WINDOW];
        });
    }
}];
[_reachability setUnreachableBlock:^(Reachability * reachability) {

    NSLog(@"Offline");

    if (weakSelf.appIsOnline)
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:OFFLINE_STATE_NOTIFICATION object:nil];
        weakSelf.appIsOnline = NO;
        dispatch_async(dispatch_get_main_queue(), ^{
            [[AppUtilities sharedUtilities] displayAlertViewWithTitle:@"Warning" andMessage:@"The internet connection appears to be offline. The app will switch to offline mode now"];
        });
    }
}];

[_reachability startNotifier];

Looks like my main UI thread is being blocked and the trigger for this is turning off the wi-fi. My thread trace is as below.

Thread 1Queue : com.apple.main-thread (serial)

#0  0x38739130 in mach_msg_trap ()
#1  0x38738f30 in mach_msg ()
#2  0x265624ec in __CFRunLoopServiceMachPort ()
#3  0x26560872 in __CFRunLoopRun ()
#4  0x264b31e8 in CFRunLoopRunSpecific ()
#5  0x264b2fdc in CFRunLoopRunInMode ()
#6  0x2f757af8 in GSEventRunModal ()
#7  0x2a71818c in UIApplicationMain ()
#8  0x00117f20 in main

Thread 3Queue : com.apple.libdispatch-manager (serial)

#0  0x3874e3c0 in kevent_qos ()
#1  0x0067d5f6 in _dispatch_mgr_invoke ()
#2  0x0066ea76 in _dispatch_mgr_thread ()

com.apple.NSURLConnectionLoader (11)

#0  0x38739130 in mach_msg_trap ()
#1  0x38738f30 in mach_msg ()
#2  0x265624ec in __CFRunLoopServiceMachPort ()
#3  0x26560872 in __CFRunLoopRun ()
#4  0x264b31e8 in CFRunLoopRunSpecific ()
#5  0x264b2fdc in CFRunLoopRunInMode ()
#6  0x25e240ae in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
#7  0x273747fc in __NSThread__start__ ()
#8  0x387ebc92 in _pthread_body ()
#9  0x387ebc06 in _pthread_start ()
#10 0x387e9a24 in thread_start ()

AFNetworking (12)#0 0x38739130 in mach_msg_trap ()

#1  0x38738f30 in mach_msg ()
#2  0x265624ec in __CFRunLoopServiceMachPort ()
#3  0x26560872 in __CFRunLoopRun ()
#4  0x264b31e8 in CFRunLoopRunSpecific ()
#5  0x264b2fdc in CFRunLoopRunInMode ()
#6  0x272a3d7c in -[NSRunLoop(NSRunLoop) runMode:beforeDate:] ()
#7  0x272f28ec in -[NSRunLoop(NSRunLoop) run] ()
#8  0x00122a2e in +[AFURLConnectionOperation networkRequestThreadEntryPoint:] at /Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m:168
#9  0x273747fc in __NSThread__start__ ()
#10 0x387ebc92 in _pthread_body ()
#11 0x387ebc06 in _pthread_start ()
#12 0x387e9a24 in thread_start ()

com.apple.CFSocket.private (13)#0   0x3874cfb4 in __select ()

#1  0x26567990 in __CFSocketManager ()
#2  0x387ebc92 in _pthread_body ()
#3  0x387ebc06 in _pthread_start ()
#4  0x387e9a24 in thread_start ()
chaithu
  • 509
  • 2
  • 7
  • 29
  • 1
    There is an issue with Reachability with latest SDK please see this question for solution .http://stackoverflow.com/questions/30743408/check-for-internet-conncetion-in-swift-2-ios-9 – Imran Sep 30 '15 at 09:13
  • @Imran Thanks for your response. I'm not getting errors anywhere. The build is successful. There are no warnings or strange logs in Xcode Console too. – chaithu Sep 30 '15 at 09:51
  • @chaithu did you ever figure this out? – FeichengMaike Oct 15 '15 at 07:04
  • @FeichengMaike Please find my answer below – chaithu Oct 16 '15 at 08:07

1 Answers1

1

I was finally able to find the real issue. It was not with reachability class. It was due to my CustomAlertView. Whenever the reachability changes, my app pops up an alert saying offline/online. It was presenting the alert view directly on my main window like this

[alertView showInView:MAIN_WINDOW];

where

#define MAIN_WINDOW         [UIApplication sharedApplication].keyWindow

In iOS 9 this is not allowed. When it tries to show, UI thread is paused. I solved it by doing this instead

[alertView showInView:MAIN_WINDOW.rootViewController.view]; 
chaithu
  • 509
  • 2
  • 7
  • 29