如何使用 UIApplication 处理 OpenURL 通知

发布于 2024-12-28 17:58:43 字数 462 浏览 0 评论 0原文

我正在尝试处理 UIApplication 通知以在当前打开的视图中获取 URL 方案。我已经尝试了几个通知,但我不知道哪个对象包含 URL 方案。

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じ违心 2025-01-04 17:58:43

正如 @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;
}

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;
}
旧时光的容颜 2025-01-04 17:58:43

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:

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文