INNER CODE UNIT · Swift

imagePickerController

cometchat/cometchat-uikit-flutter · packages/cometchat_uikit/ios/Classes/SwiftCometchatChatUikitPlugin.swift:342

    public func imagePickerController(_ picker: UIImagePickerController,
    didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        var file: [String: String] = [:]

        if let url = info[.imageURL] as? URL {
            let copied = copyToAppTmp(url)
            file = ["path": copied.path, "name": copied.lastPathComponent]
        } else if let url = info[.mediaURL] as? URL {
            let copied = copyToAppTmp(url)
            file = ["path": copied.path, "name": copied.lastPathComponent]
        } else if let image = info[.originalImage] as? UIImage {
            // Fallback: .imageURL is nil (e.g. HEIC from iCloud) — write to tmp
            let tmpDir = FileManager.default.temporaryDirectory
            let dest = tmpDir.appendingPathComponent("picked_\(Int(Date().timeIntervalSince1970 * 1000)).jpg")
            if let data = image.jpegData(compressionQuality: 0.9) {
                try? data.write(to: dest)
                file = ["path": dest.path, "name": dest.lastPathComponent]
            }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…