簡體   English   中英

迅速將UIImagePickerController呈現給照片庫后崩潰4; 隱私已添加到info.plist

[英]Crash after having presented UIImagePickerController to photo Library in swift 4 ; Privacy was added to info.plist

使用photoLibrary sourceType訪問UIImagePickerController時崩潰; 隱私已添加到info.plist

let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = .photoLibrary
self.present(myPickerController, animated: true, completion: nil)'

錯誤:

無法識別的選擇器發送到實例0x28184fb40 2019-09-09 12:45:52.126598 + 0300 ***由於未捕獲的異常'NSInvalidArgumentException'終止了應用程序,原因:'-[__ NSCFType encodeWithCoder:]:無法識別的選擇器發送到實例0x28184fb40'

嘗試這個:

    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self

    let cameraAction = UIAlertController(title: "Title", message: "Choose to upload a picture", preferredStyle: .alert)
    cameraAction.addAction(UIAlertAction(title: "Camera", style: .default, handler: {(action) in

        imagePicker.sourceType = UIImagePickerController.SourceType.camera
        self.present(imagePicker, animated: true){

        }
    }))
    cameraAction.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: {(action) in

        imagePicker.sourceType = .photoLibrary
        self.present(imagePicker, animated: true){

        }
    }))
    imagePicker.allowsEditing = true
    self.present(cameraAction, animated: true)

我假設您點擊一個按鈕來啟動UIImagePickerController 我懷疑如果您使用界面構建器設計了按鈕,則可能會將按鈕連接到多個IBAction方法。

轉到情節提要,然后右鍵單擊按鈕。 如果按鈕連接到多個“已發送事件”,那就是您的問題。 刪除不相關的內容(也許您在代碼中刪除的舊內容仍處於連接狀態)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM