ios 如何使用 UIApplication handleOpenURL 通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9000179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:29:19  来源:igfitidea点击:

How to use UIApplication handleOpenURL Notifications

iosnotificationsuiapplicationurl-scheme

提问by Omer Abbas

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.

我正在尝试处理 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];

Can someone pelase help me with this issue.

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

回答by m0rt1m3r

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

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

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

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

在您的 UIApplicationDelegate 上。他们没有匹配的通知。

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

回答by Mike K

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

application:handleOpenURL:在您的应用程序委托上调用 - 而不是通过 NSNotification。实现优选的代表方法是: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:

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