UIApplication的handleOpenURL“返回”在哪里?究竟是?

发布于 2024-08-19 02:37:43 字数 1170 浏览 7 评论 0原文

我正在处理应用程序中的自定义 URL 方案,并试图解决问题:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

我正在将 URL 传递并成功解析为应用程序中的 NSDictionary,但想知道“现在怎么办?” handleOpenURL 返回一个 BOOL 但返回什么?我很难调试,因为我还没有弄清楚如何在设备启动时让调试器在设备上运行。

我所知道的是 applicationDidFinishLaunchinghandleOpenURL 之前完成,并且看起来好像我的 rootViewController 在屏幕上。

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Load data
    [self initializeData]; 
    // Configure and show the window
    [window addSubview:[navigationController view]];    
    [window makeKeyAndVisible];
}

无论如何,现在我的 appDelegate 中有这个 NSDictionary 对象,您如何将它传递给 rootViewController 以便它可以在其详细视图中对其执行某些操作?我会在handleOpenURL的return YES;之前调用吗?

[[navigationController topViewController] addItemWithDictionary:theDictionary];

或者,我应该在我的appDelegate中创建一个NSDictionary属性,然后在“Return YES;”之后调用从我的 rootViewController (或 detailViewController - 还没有弄清楚是哪一个)中检索它。如果是这样,触发因素是什么?我不清楚handleOpenUrl 的回报将走向何方……以及它们对我有什么价值(如果有的话)。

谢谢!

I'm working on a handling a custom URL Scheme in an app and am trying to sort out:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

I'm passing and successfully parsing a URL into an NSDictionary in my app but wondering "what now?" handleOpenURL returns a BOOL but to what? It's hard for me to debug as I haven't figure out how to have debugger running on device when it fires.

All I do know is that applicationDidFinishLaunching completes before handleOpenURL and it appears as though my rootViewController is on screen.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Load data
    [self initializeData]; 
    // Configure and show the window
    [window addSubview:[navigationController view]];    
    [window makeKeyAndVisible];
}

Anyway, so, now I have this NSDictionary object in my appDelegate, how would you pass it to the rootViewController so it can do something with it in its detail view? Would I call

[[navigationController topViewController] addItemWithDictionary:theDictionary];

before handleOpenURL's return YES; Or, should I create an NSDictionary property in my appDelegate and then after "Return YES;" retrieve it from my rootViewController (or detailViewController - haven't worked out which yet). If so what's the trigger? It's not clear to me where handleOpenUrl's returns are heading...and what, if any, value they have to me.

Thanks!

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

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

发布评论

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

评论(3

不美如何 2024-08-26 02:37:43

看看这里关于 didFinishLaunchingWithOptions

http 的 建议://www.iphonedevsdk.com/forum/iphone-sdk-development/31742-handleopenurl-not-known.html

我使用了几种方法来传递数据,具体取决于条件我把它混合起来。

  1. 保持全局,这样你就不必担心通过。

  2. 使用通知消息中心使用带有通知对象的观察者模式来注册/发布您的数据。

  3. 将 URL 保存到 NSUserDefaults(也是一个字典,但您不必管理它)。

最近我不得不在 UIWebView 上做类似的事情以及过滤一些 URL 数据的处理。我必须在 NSURL 上对 WebViewCache 和 setSharedCache 进行子类化。我强烈怀疑这也适用于您的问题,通过使用 shouldStartLoadWithRequest 检索数据。

Take a look at the suggestion here about didFinishLaunchingWithOptions

http://www.iphonedevsdk.com/forum/iphone-sdk-development/31742-handleopenurl-not-called.html

There are a couple of approaches I've used to pass data around, and depending on the conditions I mix it up.

  1. Keep a global around so you don't have to worry about passing.

  2. Register/post your data using the Observer pattern with a Notification object using the notification message center.

  3. Save URLs to NSUserDefaults (also a dictionary, but you don't have to manage it).

Recently I had to do something similar on a UIWebView and the handling of filtering some URL data. I had to subclass WebViewCache and setSharedCache on the NSURL. I strongly suspect this would apply to your problem as well by retrieving the data with shouldStartLoadWithRequest.

归属感 2024-08-26 02:37:43

从其他应用程序或移动 safari(非越狱设备)调试 openurl 的一个方便技巧是子类化 UIApplication 并覆盖一些未记录的方法,抱歉我不记得名称了,但你可以在 ericasadun.com 上挖掘它们,名称将相当明显的。

当您通过 xcode 启动应用程序并点击 home springboard 时,不会终止该进程,因为它是由 xcode 启动的(据我所知),因此您可以启动其他应用程序并调用 openurl,同时仍附加到调试器。

a handy tip for debugging openurl from other apps or mobile safari (non jailbroken device) is to subclass UIApplication and override a few undocumented methods, sorry i dont remember names offhand but you can dig them up at ericasadun.com, the names will be fairly obvious.

when you launch the app through xcode and hit home springboard doesnt kill the process because it was started by xcode (afaik) so you can launch other apps and call openurl while still being attached to the debugger.

柳若烟 2024-08-26 02:37:43

我想我可能已经回答了我自己的问题,但如果您有其他想法,我很想听听!

我认为我需要继续在 handleOpenURL 中进行处理,并将字典转换为一个对象,然后将其添加到 rootViewController 用来构建其表视图的 appDelegate 数组中。显然需要进行一些验证和验证在自动填充数组之前由用户确认。我想这也会发生在handleOpenURL 的范围内?

I think I may have answered my own question but if you have other ideas I'd love to hear them!

I think I need to continue processing in handleOpenURL and turn the dictionary into an object that is then added to my appDelegate's array that rootViewController is using to build it's table view. Obviously need to work out some validation & confirmation on user's part before auto populating array. I guess that would also happen within confines of handleOpenURL?

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