ModelManager
class ModelManager : NSObject
管理 MLKit 功能使用的模型。
-
返回
ModelManager
实例。声明
Swift
class func modelManager() -> Self
返回值
一个
ModelManager
实例。 -
不可用。使用
modelManager()
类方法。 -
检查是否已下载给定模型。
声明
Swift
func isModelDownloaded(_ remoteModel: MLKRemoteModel) -> Bool
参数
remoteModel
要检查下载状态的模型。
返回值
给定模型是否已下载。
-
将给定模型从服务器下载到设备上的本地目录。使用
isModelDownloaded(_:)
检查模型的下载状态。如果调用此方法并且模型已下载,系统会请求检查是否有更新的模型版本可供下载。下载模型的新版本(如果有)。如需了解此方法何时完成,请观察
MLKModelDownloadNotifications.h
中定义的.mlkitModelDownloadDidSucceed
和.mlkitModelDownloadDidFail
通知。 如果已下载最新模型,则完成操作,无需执行额外的操作,并发布.mlkitModelDownloadDidSucceed
通知,指示模型已准备就绪,可供使用。声明
Swift
func download(_ remoteModel: MLKRemoteModel, conditions: MLKModelDownloadConditions) -> Progress
参数
remoteModel
要下载的模型。
conditions
下载模型的条件。
返回值
模型的下载进度。
-
从设备中删除下载的模型。
声明
Swift
func deleteDownloadedModel(_ remoteModel: MLKRemoteModel, completion: @escaping (Error?) -> Void)
参数
remoteModel
要删除的已下载模型。
completion
使用指定的
error
成功完成或失败时,对主队列进行回调的处理程序。