gpt4 book ai didi

ios - 在 Swift 中使用 LSApplicationWorkspace

转载 作者:搜寻专家 更新时间:2023-10-31 08:16:32 24 4
gpt4 key购买 nike

我已将 MobileCoreServices.framework 添加到我的 Xcode 项目中,并在我的文件顶部添加语句 import MobileCoreServices

我有这行代码

让测试 = LSApplicationWorkspace.defaultWorkSpace()

而 xcode 说 Unresolved Identifier LSApplicationWorkspace

我尝试清理和重建项目。有什么想法吗?

最佳答案

要点 1: LSApplicationWorkspace 是私有(private) api,因此如果您使用它并将您的应用上传到应用商店,它将被拒绝。

第 2 点:如果您有任何内部应用程序并且仍想在您的应用程序中使用它,那么下面是使用它的方法。

  1. 在您的包中添加 MobileCoreServices 框架
  2. 使用与此处“https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MobileCoreServices.framework/LSApplicationWorkspace.h”中提供的代码完全相同的代码创建 LSApplicationWorkspace.h 文件。
  3. 现在将这个 LSApplicationWorkspace.h 文件添加到您的包中
  4. 为您的 swift 应用创建桥接头
  5. 在桥接 header 中添加#import "LSApplicationWorkspace.h"
  6. 现在在您的当前文件中添加import MobileCoreServices 并添加您的代码let test = LSApplicationWorkspace.defaultWorkSpace(),它将正常工作。

注意:要使用任何私有(private) header ,您必须将其 .h 文件包含到您的代码中。您可以通过在 google 中搜索“runtime headers”来找到任何私有(private) header 。您将获得所有运行时 header 。要在您的 swift 代码中包含该 header ,您需要通过 bridging-header。

关于ios - 在 Swift 中使用 LSApplicationWorkspace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35807764/

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