通过iOS应用程序进行深度链接以编程方式打开相机?

4
我想在我的应用程序中创建一个IBAction来打开iOS本机相机应用程序,但我似乎找不到相机应用程序的地址。我知道对于消息,它是:UIApplication.shared.open(URL(string:“sms:”)!,options:[:],completionHandler:nil)。有人知道正确的scheme是哪个吗?

FYI - 使用 open 不会在“你的应用程序”中打开请求的应用程序。它会启动应用程序并将您的应用程序置于后台。 - rmaddy
@rmaddy,这正是我想做的!感谢您让我知道。 - Theo Strauss
1
无法通过编程从您的应用程序启动相机应用程序。 - Blazej SLEBODA
仍然无法以编程方式启动相机应用程序吗? - Daniel T.
3个回答

5
我建议您采用一种干净的方式来实现这一点:
let cameraVc = UIImagePickerController()
cameraVc.sourceType = UIImagePickerControllerSourceType.camera
self.present(cameraVc, animated: true, completion: nil)

在这种情况下,您必须将以下内容添加到Info.plist中:
<key>NSCameraUsageDescription</key>
<string>whatever</string>

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()
    }
}

0

在您的 Info.plist 中添加 NSCameraUsageDescription 后,Swift 5 版本:

let cameraVc = UIImagePickerController()
cameraVc.sourceType = UIImagePickerController.SourceType.camera
self.present(cameraVc, animated: true, completion: nil)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接