如何使用UIApplication handleOpenURL通知

时间:2012-01-25 09:16:40

标签: ios notifications uiapplication url-scheme

我正在尝试处理UIApplication Notifications以在当前打开的视图中获取URL Schemes。我尝试了几个通知,但我不知道哪个对象包含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];

有人可以帮我解决这个问题。

2 个答案:

答案 0 :(得分:8)

正如@Mike K所提到的,你必须实施以下一种(或两种)方法:

- application:handleOpenURL:
- application:openURL:sourceApplication:annotation:
在您的UIApplicationDelegate上。没有匹配的通知。

以下示例:

-(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;
}

答案 1 :(得分:2)

在您的应用程序委托上调用

application:handleOpenURL: - 而不是通过NSNotification。要实现的首选委托方法是:application:openURL:sourceApplication:annotation:

可在此处找到更多信息: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:handleOpenURL