Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top