【问题标题】:Open Camera Programmatically Through iOS App - Deep Link?通过 iOS 应用程序以编程方式打开相机 - 深层链接?
【发布时间】:2018-01-20 21:47:53
【问题描述】:

我想创建一个 IBAction 以在我的应用中打开 iOS 原生相机应用,但我似乎无法在线找到相机应用的地址。

我知道消息是:UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)

有谁知道哪个是正确的方案?

【问题讨论】:

  • 仅供参考 - 使用 open 不会“在您的应用程序中”打开请求的应用程序。它会启动应用并将您的应用置于后台。
  • @rmaddy 这正是我想做的!谢谢你告诉我
  • 不可能从您的应用程序中以编程方式午餐相机应用程序。
  • 仍然无法以编程方式启动相机应用程序吗?

标签: ios swift deep-linking ios-camera


【解决方案1】:

我建议你按照干净的方式这样做:

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

在这种情况下,您必须添加到Info.plist:

<key>NSCameraUsageDescription</key>
<string>whatever</string>

【讨论】:

    【解决方案2】:

    这里我们建议您使用以下 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()
        }
    }
    

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-26
        • 2016-05-10
        • 2018-02-12
        • 1970-01-01
        • 2016-10-21
        • 1970-01-01
        • 2020-10-04
        • 1970-01-01
        相关资源
        最近更新 更多