1.swift3.0中调用相机和相册会导致崩溃
1.需要在info.plist
文件中加入两个键值对,如下:
Privacy - Photo Library Usage Description
Privacy - Camera Usage Description
2.UIImagePickerControllerSourceType
枚举
1
2
3
4
5
public enum UIImagePickerControllerSourceType : Int {
case photoLibrary
case camera
case savedPhotosAlbum
}
3.功能实现Demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
@objc fileprivate func AddPhotoClick(){
if !UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
return
}
let picVc = UIImagePickerController()
picVc.sourceType = .photoLibrary
picVc.allowsEditing =
true
picVc.
delegate = self
present(picVc,animated:
true,completion: nil)
}
4.UIImagePickerController
协议
1.需要遵循2个
协议:
UIImagePickerControllerDelegate
5.常用imagePickerController代理
方法
1
2
3
4
5
6
extension LXRComposeViewController : UIImagePickerControllerDelegate,UINavigationControllerDelegate{
func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediaWithInfo info: [
String : Any]) {
LXRLog(message: info)
}
}
6.打印信息