iOS 4 中的多任务感知应用程序和自定义 URL 方案

发布于 2024-09-08 03:13:20 字数 956 浏览 2 评论 0原文

我正在尝试安全地实现 OAuth,如下所示: http:// fireeagle.yahoo.net/developer/documentation/oauth_best_practice#custom-url-osx。我似乎遇到了绊脚石,因为我无法弄清楚如何处理在后台启动我的应用程序的网址。

我已经注册了我的应用程序来处理 oauthtest。我已确认 oauthtest:// 和 oauthtest://callbacktest 都会启动我的应用程序,并在我的应用程序未在后台运行时按预期运行。

我正在实现

application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

当我的应用程序冷启动时成功调用它。我可以轻松地将 url 传递到我的应用程序。

但是,如果我的应用程序已经在后台运行,则既不会

application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

被调用,也不会

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

被调用,并且我无法将参数作为 URL 的一部分传递给我的应用程序。

有谁知道如何通过自定义 url 方案获取传递到后台应用程序的参数?

我知道我可以通过禁用多任务处理来解决这个问题,但出于明显的原因我宁愿不这样做。提前致谢。

I'm trying to implement OAuth securely as detailed here: http://fireeagle.yahoo.net/developer/documentation/oauth_best_practice#custom-url-osx. I seem to have hit a stumbling block, as I am unable to figure out how to handle a url which launches my application when in the background.

I have registered my application to handle oauthtest. I have confirmed that oauthtest:// and oauthtest://callbacktest both launch my application and operate as intended when my application is not running in the background.

I am implementing

application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

which is successfully called when my application starts up cold. I can easily get the url passed to my application.

However, if my application is already running in the background, neither

application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

nor

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

is called and I have no way of getting the parameters passed to my application as part of the URL.

Does anyone know how to get the parameters passed to a backgrounded application by a custom url scheme?

I am aware that I could work around this issue by disabling multitasking, but I would rather not do that for obvious reasons. Thanks in advance.

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

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

发布评论

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

评论(1

独自←快乐 2024-09-15 03:13:20

下面是一些似乎对我有用的示例代码,在 iOS4 中进行了测试:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
     NSLog(@"handleOpenURL - %@", [url absoluteURL]);
     return YES;    
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    NSLog(@"applicationDidFinishLaunching");
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"didFinishLaunchingWithOptions - %@", [launchOptions objectForKey:@"UIApplicationLaunchOptionsURLKey"]);
    return NO;
}

如果我第一次启动应用程序,didFinishLaunching: 会处理 URL。如果我随后将应用程序置于后台,返回 Safari,然后点击将应用程序带回前台的链接,则 handleOpenURL: 会处理该 URL。祝你好运!

Here's some sample code that seemed to work for me, tested in iOS4:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
     NSLog(@"handleOpenURL - %@", [url absoluteURL]);
     return YES;    
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    NSLog(@"applicationDidFinishLaunching");
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"didFinishLaunchingWithOptions - %@", [launchOptions objectForKey:@"UIApplicationLaunchOptionsURLKey"]);
    return NO;
}

If I launch the application for the first time, didFinishLaunching: handles the URL. If I then put the app in the background, go back to Safari, and tap a link that brings the app back into the foreground, then handleOpenURL: takes care of the URL. Good luck!

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