在 Swift 中使用 LSApplicationWorkspace [英] Using LSApplicationWorkspace in Swift

查看:61
本文介绍了在 Swift 中使用 LSApplicationWorkspace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've added MobileCoreServices.framework to my Xcode project, and have the statement import MobileCoreServices in top of my file.

我有这行代码

让 test = LSApplicationWorkspace.defaultWorkSpace()

而xcode说Unresolved Identifier LSApplicationWorkspace

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

I tried cleaning and rebuilding the project. Any ideas?

推荐答案

第1点: LSApplicationWorkspace 是私有的api,所以如果你使用这个并将你的应用上传到应用商店,它会被拒绝.

Point 1: LSApplicationWorkspace is private api, so if you use this and will upload your app to app store, it will get rejected.

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

Point 2: If you are having any in-house app and still want to use this in your app, then below is the way to use it.

  1. 在你的包中添加 MobileCoreServices 框架
  2. 使用与此处提供的代码完全相同的代码创建 LSApplicationWorkspace.h 文件https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MobileCoreServices.framework/LSApplicationWorkspace.h".
  3. 现在将此 LSApplicationWorkspace.h 文件添加到您的包中
  4. 为您的 swift 应用创建桥接头
  5. 在您的桥接头中添加 #import "LSApplicationWorkspace.h"
  6. 现在在你的当前文件中添加import MobileCoreServices 并添加你的代码let test = LSApplicationWorkspace.defaultWorkSpace(),它就可以正常工作了.
  1. Add MobileCoreServices Framework in your bundle
  2. Create LSApplicationWorkspace.h file with the code exactly same as the code provided at here "https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MobileCoreServices.framework/LSApplicationWorkspace.h".
  3. Now add this LSApplicationWorkspace.h file into your bundle
  4. Create bridging header for your swift app
  5. Add #import "LSApplicationWorkspace.h" in your bridging header
  6. Now add import MobileCoreServices in your current file and add your code let test = LSApplicationWorkspace.defaultWorkSpace(), it will work fine.

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

NOTE: For using any private header, you must have to include its .h file into your code. You can find any private headers by searching "runtime headers" in google. You will get all runtime headers. And to include that header in your swift code, you need to go via bridging-header.

这篇关于在 Swift 中使用 LSApplicationWorkspace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆