0

I've had a look around to try and work out how I can receive a notification for when a URL has been loaded by the shared application, and it appears I need to create a delegate which inherits from UIApplicationDelegate and override some of the methods, however I can't seem to work out which methods to override and how I would implement them?

poupou
  • 43,413
  • 6
  • 77
  • 174
davoc bradley
  • 220
  • 2
  • 16

1 Answers1

2

Your application already have a delegate that inherits from UIApplicationDelegate. That's generally inside the (MonoDevelop generated) AppDelegate.cs file and where the required FinishedLaunching method is present.

I'm not 100% sure what you want exactly want to accomplish (any reference?) but you can override the local and remote notification, e.g.

public override void ReceivedLocalNotification (UIApplication application, UILocalNotification notification)
{
    // ...
}

public override void ReceivedRemoteNotification (UIApplication application, NSDictionary userInfo)
{
    // ...
}

but if you want to know if an URL was provided when opening your application then this should be done inside the (already overridden) FinishedLaunching method. That last part, to use to supplied information inside the NSDictionary, is explained in Apple documentation.

poupou
  • 43,413
  • 6
  • 77
  • 174
  • Hi Poupou, Sorry, I should have been more clear :-) What I'm doing is using UIApplication.SharedApplication.OpenUrl(url) to open a web url, but I want to show an activity spinner until the website has actually been loaded, so I need to be notified when the site has loaded. Thanks for your help by the way! – davoc bradley Jan 11 '12 at 09:42
  • Sorry I'm not sure I understand correctly. If you use `OpenUrl` to open a web url (e.g. an http://www.x.com/page.html) then Safari (or the application registred for the scheme) will be launched immediately, hiding your application (and any spinner) by moving it into the background. Maybe you want to display html from your app ? then you should look at `UIWebView` http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html – poupou Jan 11 '12 at 12:11
  • Hi, that's not necessarily the case, as some links do not open up safari, they just use safari to launch a link, which then prompts the user to perform an action, which is what I'm doing. Do you know if there is a way to notify my application when the link has loaded? Cheers in advance! – davoc bradley Jan 11 '12 at 13:42
  • Sorry, no way that I know of. Your application is being moved to the background and the one registred for the scheme gets to the foreground. That application could be anything and I don't recall any mandatory (or suggested) way to expose such event in applications. – poupou Jan 11 '12 at 13:49
  • Hi Poupou, if your OpenUrl call is a url to install an app it doesn't actually move your application into the background, as it still continues to be active, and that open url action actually opens up a dialogue box asking the user if they want to install the application. The problem I'm having is that the dialog box sometimes takes a while to open, and so my user could navigate away from the page they were just on. – davoc bradley Jan 11 '12 at 14:07
  • Hard to be sure without a test case. You can *probably* fake it by starting your spinner, call `OpenUrl`, then when the dialog pops up I *suspect* you'll be notified that you're not the main app. Try to override everything in `UIApplicationDelegate` and add `Console.WriteLine("method name")` in them. With luck you'll find one that gets trigerred at the right time. YMMV – poupou Jan 11 '12 at 14:18
  • Ok, cheers, I'll give that a go :-) Thanks for your help, will mark it as correct if I get it all working :-) – davoc bradley Jan 11 '12 at 14:24
  • Awesome! That worked, it was int OnResignActivation. I just added an event to the AppDelegate and then raised that when that is called and then put a handler where my code is to hide the spinner :-) Thanks for your help!! – davoc bradley Jan 11 '12 at 14:34