Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use UIApplication handleOpenURL Notifications

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.

like image 355
Omer Abbas Avatar asked Jan 25 '12 09:01

Omer Abbas


2 Answers

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;
}
like image 87
m0rt1m3r Avatar answered Sep 22 '22 22:09

m0rt1m3r


application:handleOpenURL: is called on your application delegate - not via a NSNotification. the preferred delegate method to implement is: application:openURL:sourceApplication:annotation:.

more info can be found here: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:handleOpenURL:

like image 2
Mike K Avatar answered Sep 19 '22 22:09

Mike K