OpenUrl freezes app for over 10 seconds OpenUrl freezes app for over 10 seconds ios ios

OpenUrl freezes app for over 10 seconds


I noticed the same problem when calling -[UIApplication openUrl:] from the Application Delegate didReceiveRemoteNotification: or didFinishLaunchingWithOptions: since iOS 7.

I solved it by delaying the call a bit using GCD :

// objcdispatch_async(dispatch_get_main_queue(), ^{    [[UIApplication sharedApplication] openURL:url];});

It let iOS some time to finish application initialization and the call is then performed without any problem. Don't ask me why.

Does this works for you ?

As this answer is often seen, I added the swift version:

// swiftdispatch_async(dispatch_get_main_queue()) {    UIApplication.sharedApplication().openURL(url)}


I have seen the same issue in iOS 7. My solution is only slightly different from those already proposed. By using performSelector with just a 0.1 second delay, the app immediately opens the URL.

[self performSelector:@selector(methodToRedirectToURL:) withObject:url afterDelay:0.1];


Had the exact same symptoms that you described: worked fine on iOS6, but ~10 second hang on iOS7. Turns out to be a threading issue.

We were issuing the [UIApplication sharedApplication] openURL directly from the AppDelegate method applicationDidBecomeActive(). Moving this to a background thread instantly solved the problem:

- (void)applicationDidBecomeActive:(UIApplication *)application{    ...    // hangs for 10 seconds    // [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];    // Fix: use threads!    [NSThread detachNewThreadSelector:@selector(openbrowser_in_background:) toTarget:self withObject:url];    ...}- (void)openbrowser_in_background:(NSString *)url{    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];}