我想在我的应用程序中创建一个IBAction来打开iOS原生相机应用,但我似乎无法在线找到相机应用的地址。
我知道消息是:UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
有谁知道哪个是正确的方案?
答案 0 :(得分:3)
我建议你按照干净的方式这样做:
let cameraVc = UIImagePickerController()
cameraVc.sourceType = UIImagePickerControllerSourceType.camera
self.present(cameraVc, animated: true, completion: nil)
在这种情况下,您必须添加到Info.plist
:
<key>NSCameraUsageDescription</key>
<string>whatever</string>
答案 1 :(得分:0)
在这里,我们建议您使用以下github:
https://github.com/shantaramk/AttachmentHandler
!。 1.将AttachmentHandler文件夹拖放到项目文件夹中
func showCameraActionSheet() {
AttachmentHandler.shared.showAttachmentActionSheet(viewController: self)
AttachmentHandler.shared.imagePickedBlock = { (image) in
let chooseImage = image.resizeImage(targetSize: CGSize(width: 500, height: 600))
self.imageList.insert(chooseImage, at: self.imageList.count-1)
self.collectionView.reloadData()
}
}
答案 2 :(得分:0)
在您的Info.plist中添加NSCameraUsageDescription后,迅速5版本:
let cameraVc = UIImagePickerController()
cameraVc.sourceType = UIImagePickerController.SourceType.camera
self.present(cameraVc, animated: true, completion: nil)
答案 3 :(得分:-4)