我已经将MobileCoreServices.framework添加到我的Xcode项目中,并在文件顶部添加了语句import MobileCoreServices
。
我有以下代码行:
let test = LSApplicationWorkspace.defaultWorkSpace()
但是Xcode提示未解决标识符LSApplicationWorkspace
我已尝试清理并重建项目。有任何想法吗?
我已经将MobileCoreServices.framework添加到我的Xcode项目中,并在文件顶部添加了语句import MobileCoreServices
。
我有以下代码行:
let test = LSApplicationWorkspace.defaultWorkSpace()
但是Xcode提示未解决标识符LSApplicationWorkspace
我已尝试清理并重建项目。有任何想法吗?
注意点1:LSApplicationWorkspace是私有API,如果您使用此API并上传您的应用程序到应用商店,它将被拒绝。
注意点2:如果您拥有任何企业内部应用程序并仍想在您的应用程序中使用此API,则可以按以下方式使用。
MobileCoreServices
框架。LSApplicationWorkspace.h
的文件,其代码与此处提供的代码完全相同 "https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MobileCoreServices.framework/LSApplicationWorkspace.h"。LSApplicationWorkspace.h
文件添加到您的包中。#import "LSApplicationWorkspace.h"
。import MobileCoreServices
并添加您的代码 let test = LSApplicationWorkspace.defaultWorkSpace()
,它将正常工作。注意:要使用任何私有头文件,必须将其 .h
文件包含在您的代码中。您可以通过在谷歌中搜索“运行时头文件”来查找任何私有头文件。您将获得所有运行时头文件。要在您的Swift代码中包含该头文件,您需要通过桥接头文件进行操作。
LSApplicationWorkspace.h
并导入代码后,出现了多个错误,显示“未知类型名称”,例如:“LSInstallProgressDelegate”。我是不是漏掉了什么? - user3191334let LSApplicationWorkspace_class:AnyObject = NSClassFromString("LSApplicationWorkspace")! as AnyObject
let workspace = LSApplicationWorkspace_class.perform(NSSelectorFromString("defaultWorkspace"))! as AnyObject