2

Can anyone think of an explanation for a case where openURL returns false but the app is opened successfully?

NSString *appUrlPathStr = @"";
NSURL *appUrlPath = [NSURL URLWithString:appUrlPathStr];

if([[UIApplication sharedApplication] canOpenURL:appUrlPath]) {
    if ([[UIApplication sharedApplication] openURL:appUrlPath]) {
        NSLog(@"app opened");
    } else {
        NSLog(@"app not opened");
    }
}

Note: did not include the url string itself in the code here.

Roy K
  • 3,319
  • 2
  • 27
  • 43

3 Answers3

2

I was not only having the same issue but to make things worse the other app would only open when it wasn't suspended or inactive (i.e. fresh start)

For me the problem was that I didn't add the custom scheme I wanted to query to my Info.plist file.

As soon as I added it to the LSApplicationQueriesSchemes entry the problems went away.

query custom scheme

For more info, see: http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/

Hope this helps!

LuisCien
  • 6,362
  • 4
  • 34
  • 42
0

A logic explanation for what I have experienced:

I checked the device logs and I notices that the app I am trying to open, shoots logs and get stuck way before it reaches the foreground. (moreover, it happens while the original app is in foreground).

Therefore, openURL hangs and reaches its timeout, then it returns false and the app I am trying to open eventually opens.

Conclusion, I need to check the app I am opening and see why it hangs before it becomes active.

Thanks everyone, and I hope it will help others.

Roy K
  • 3,319
  • 2
  • 27
  • 43
-1

I have seen the same issue in iOS 7. My solution is:

1)

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

or

2)

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