How to use UIApplication handleOpenURL Notifications

Omer Abbas picture Omer Abbas · Jan 25, 2012 · Viewed 23.7k times · Source

I am trying to handle UIApplication Notifications to get URL Schemes in current open view. I have tried several notifications but i don't know which object contains the URL Schemes.

 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    //[nc addObserver:self selector:@selector(DocumentToDropboxDelegate) name:UIApplicationWillResignActiveNotification object:nil];
    [nc addObserver:self selector:@selector(DocumentToDropboxDelegate) name:UIApplicationDidFinishLaunchingNotification object:nil];

Can someone pelase help me with this issue.

Answer

m0rt1m3r picture m0rt1m3r · Jan 25, 2012

As @Mike K mentioned you'll have to implement one (or both) of the following methods:

- application:handleOpenURL:
- application:openURL:sourceApplication:annotation:

on your UIApplicationDelegate. There is no matching notification for them.

Example below:

-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if (url != nil && [url isFileURL]) {
        [self.viewController handleOpenURL:url];
    }
    return YES;
}

//Deprecated
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    if (url != nil && [url isFileURL]) {
        [self.viewController handleOpenURL:url];
    }
    return YES;
}