首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用相机快速拍摄照片后创建警报

如何在使用相机快速拍摄照片后创建警报
EN

Stack Overflow用户
提问于 2018-03-13 07:22:07
回答 4查看 868关注 0票数 1

我有一个按钮,当我录音按钮相机,并采取pictures.after拍照,我需要显示警报到user.the警报部分不工作。在这里输入图像描述

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2018-03-19 12:37:45

这段代码适用于我,我能够解决我的问题。

代码语言:javascript
复制
func cameraAsscessRequest() {
        if AVCaptureDevice.authorizationStatus(for: AVMediaType.video) ==  AVAuthorizationStatus.authorized {

    } else {
        AVCaptureDevice.requestAccess(for: AVMediaType.video) { granted -> Void in

        }
    }
}

func image(){

    if !UIImagePickerController.isSourceTypeAvailable(.camera){
        let alertController = UIAlertController.init(title: nil, message: "Device has no camera.", preferredStyle: .alert)
        let okAction = UIAlertAction.init(title: "Alright", style: .default, handler: {(alert: UIAlertAction!) in
        })
        alertController.addAction(okAction)
        self.present(alertController, animated: true, completion: nil)
    }
    else{
        //other action
        imagePicker.sourceType = .camera
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        imagePicker.allowsEditing = false
        self.present(imagePicker,animated: true,completion: nil)
    }



}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
   if let pickedimage =     info[UIImagePickerControllerOriginalImage] as?UIImage{
    let alert = UIAlertController(title: "",
                                  message: "Are you sure you want to upload invoice ?",
                                  preferredStyle: .alert)

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
        UIAlertAction in
        Print("Camera On")

    }
    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) {
        UIAlertAction in
        print("lll")
    }


    alert.addAction(cancelAction)
    alert.addAction(okAction)

    self.dismiss(animated: true, completion: nil)

    self.present(alert, animated: true, completion: nil)

    }
}
票数 1
EN

Stack Overflow用户

发布于 2018-03-13 07:23:46

为此,您需要对AlertController的当前方法进行调整,然后显示您自己的方法,将用户输入转发到原始警报。反正我也不喜欢这个。

票数 0
EN

Stack Overflow用户

发布于 2018-03-13 07:25:10

在添加操作后添加这一行:

代码语言:javascript
复制
self.present(alert, animated: true, completion: nil)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49250402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档