0
NSURL *url = [NSURL URLWithString:@"valid_webcal_url"];
if (![[UIApplication sharedApplication] openURL:url])
{
    // failure callback
    NSLog(@"%@%@",@"Failed to open url:",[url description]);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:LCHLocalizedString(@"SUBSCRIBE_ERROR", nil) message:nil delegate:self cancelButtonTitle:@"Okay" otherButtonTitles: nil];
    [alert show];
}

So I've figured out how to see if there was an error loading the webcal, but how can I know when the webcal was loaded successfully? I display a loader when the "subscribe" button is tapped and just need to know when to turn it off.

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • Why are you raping poor `NSLog()`? Format strings can contain constant parts, and `NSLog(@"Failed to open url: %@", url);` is **much more readable.** –  Feb 19 '13 at 18:13
  • 1
    Doesn't openURL put your app in the background anyway? – Mundi Feb 19 '13 at 18:42
  • Apparently when using the webcal protocol it does not. Funky, I know but your comment helped me find a workable solution. – Jacksonkr Feb 19 '13 at 20:13

2 Answers2

1

As already stated in the comments this will put your app in the background with no guaranteed means to automatic return.

Assuming you actually want to invoke a web page (as opposed to doing a web api call) you should probably create a custom subclass of UIViewController with an embedded UIWebView.

Setting your subclass as a delegate of the UIWebView will allow you to react to failure/success. You can even intercept and stop UIWebView calls with - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

zbu
  • 57
  • 5
1

Because this is using openURL to retrieve an item using the webcal protocol, there is no visual separation of app and webcal retrieval.

What I'm having to do is listen for the notification UIApplicationWillResignActiveNotification after calling openURL and when the notification is fired I assume it's the webcal taking over from my openURL call.

This is tricky business and a rudimentary fix but hey, it works! Thanks for all help/suggestions.

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284