You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS 15中替代kUTTypeImage的UTTypeImage需要导入哪个库?

你需要导入UniformTypeIdentifiers库,才能让Xcode识别UTTypeImage相关的新常量。

在你的Swift文件头部添加如下导入语句即可:

import UniformTypeIdentifiers

如果你的应用需要兼容iOS 15以下的系统版本,推荐使用如下兼容写法,不需要修改原有业务逻辑:

import UIKit
import UniformTypeIdentifiers
import MobileCoreServices // 低版本iOS仍需导入该库使用kUTType系列常量

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    guard let mediaType = info[.mediaType] as? String else { return }
    switch mediaType {
    case (try? UTType.image.identifier) ?? String(kUTTypeImage):
        // 图片处理逻辑
    case (try? UTType.movie.identifier) ?? String(kUTTypeMovie):
        // 视频处理逻辑
    default:
        break
    }
}

补充说明:目前苹果官方更推荐使用UTType.image.identifier的写法替代顶层常量UTTypeImage,兼容性和可读性更强。


内容的提问来源于stack exchange,提问作者manman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 03:39:02