ios - iOS App的AppDelegate中open URL方法的区别

标签 ios swift appdelegate

我在我的 AppDelegate 文件中使用这个方法来处理通过我的 URL 方案打开的应用程序

func application(_ application: UIApplication, open url: URL, 
                 sourceApplication: String?, annotation: Any) -> Bool {}

后来我添加了其他方法(需要iOS 9.0)

func application(_ application: UIApplication, open url: URL,
                 options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {} 

现在我看到第二种方法处理所有应用启动。

  1. 这些方法有什么区别?
  2. 我是否应该用相同的逻辑填充它们,以便我的第一个方法只在 iOS 8 设备上执行。
  3. 如果我对支持 iOS 8 不感兴趣,我可以删除我的第一个方法吗

最佳答案

第一种方法从iOS 4.0 到iOS 9.0 都支持。现在已弃用。 从 9.0 开始,iOS 为 openURL 提供了新方法,这是您的第二种方法。

这两种方法的目的是一样的。因此,如果想同时支持 iOS 8 而不是保留这两种方法,请删除已弃用的方法。

您可以在 UIKit 框架 -> UIApplication.h 中看到这一点(检查下图)

enter image description here

关于ios - iOS App的AppDelegate中open URL方法的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49253478/

相关文章:

ios - RXSwift 如何为具有返回值的委托(delegate)方法创建包装器

ios - 构建在一天中第一次运行时停止并显示 Restore the connection to "iPhone 5"and run "Quiz"again

swift repl 在 linux 的 windows 子系统中不起作用

swift - 如何调整宽度 tabBarController 并使其半径

数组作为 Swift 字典中的值 : Cannot append values

ios - 当应用程序进入后台并进入前台时调用 UIViewController 方法

iphone - AudioServicesPlayAlertSound 在应用程序 :didReceiveRemoteNotification: 期间不播放自定义声音

ios - 使用带有 MBProgressHUD 的自定义动画

ios - 合并 AppDelegate_iPhone 和 AppDelegate_iPad

swift - 避免因启动画面或错误的 Controller 激活而丢失小部件发送的通知