gpt4 book ai didi

ios - 如何关闭/恢复对 openURL 方法的调用

转载 作者:行者123 更新时间:2023-11-28 21:30:58 29 4
gpt4 key购买 nike

当通过 URL 方案打开应用程序时(第一次,当应用程序甚至不在后台时),应用程序中的 didFinishLaunchingWithOptions 将被调用,我们可以得到 字典 launchOptions 中的 UIApplicationLaunchOptionsURLKey

我试图在 didFinishLaunchingWithOptions 中返回 NO,但没有任何区别。

我想做的是当 url 中的参数有问题时关闭应用程序,而这个 url 是打开应用程序的 url。

假设 url myapp://&param1=2&param2=2 打开了我的应用。

在应用委托(delegate)中,我检查了有效的参数。如果参数值错误,我不希望 URL 打开我的应用程序。我想暂停那个 Action ,回到我来的地方。

我尝试在 didFinishLaunchingWithOptionsopenURL 中返回 NO 但没有一个给我想要的东西。

if (![self checkURL:launchOptions[UIApplicationLaunchOptionsURLKey]]) {
DLog(@"Don't launch the app/close the app");
return NO;
}

如果 url 无效,有没有办法关闭应用程序(或至少让应用程序进入后台)?

最佳答案

以编程方式关闭应用程序在技术上违反了 Apple 的人机界面指南 (source)。官方推理:

Never quit an iOS app programmatically. People tend to interpret this as a crash. If something prevents your app from functioning as intended, you need to tell users about the situation and explain what they can do about it. Here are two good ways to do this:

  1. If all app features are unavailable, display a screen that describes the situation and suggests a correction. The information gives feedback to users and reassures them that there’s nothing wrong with your app. It also puts users in control, letting them decide whether they want to take corrective action and continue using your app or switch to another app.
  2. If only some app features are unavailable, display either a screen or an alert when people try to use the feature. Otherwise, people should be able to use the rest of the app. If you decide to use an alert, be sure to display it only when people try to access the feature that isn’t functioning.

听起来您可能需要提供某种错误,然后让用户自行采取行动。如果您确定知道用户来自何处(或者可以通过传入的 URL 参数找出),那么您可能能够提供某种自动路由回其他应用程序。

关于ios - 如何关闭/恢复对 openURL 方法的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36090366/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com