Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我的相机在iPad12.1.4上崩溃,但在iphone上工作正常_Ios_Swift - Fatal编程技术网

Ios 我的相机在iPad12.1.4上崩溃,但在iphone上工作正常

Ios 我的相机在iPad12.1.4上崩溃,但在iphone上工作正常,ios,swift,Ios,Swift,我用相机拍照,它在iphone上工作正常,但在ipad上运行时会崩溃 @IBAction func uploadPhotoButtonPressed(_ sender: UIButton) { let camera = Camera(delegate_: self) let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

我用相机拍照,它在iphone上工作正常,但在ipad上运行时会崩溃

@IBAction func uploadPhotoButtonPressed(_ sender: UIButton) {
        let camera = Camera(delegate_: self)

        let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

        let takePhoto = UIAlertAction(title: "Take Photo", style: .default) { (alert: UIAlertAction!) -> Void in
            camera.PresentPhotoCamera(self, canEdit: true)
        }

        let sharePhoto = UIAlertAction(title: "Photo Library", style: .default) { (alert: UIAlertAction!) -> Void in
            camera.PresentPhotoLibrary(self, canEdit: true)
        }

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (alert : UIAlertAction!) -> Void in

            print("Cancel")
        }

        optionMenu.addAction(takePhoto)
        optionMenu.addAction(sharePhoto)

        optionMenu.addAction(cancelAction)

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

    }

我认为你在UIAlertController中的错误是因为在iPad中你需要通过源代码视图

请检查iPad的UIAlertController代码

if let popoverController = yourAlert.popoverPresentationController {
                popoverController.sourceView = self.view //to set the source of your alert
                popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) // you can set this as per your requirement.
                popoverController.permittedArrowDirections = [] //to hide the arrow of any particular direction
            }

您也可以在模拟器中检查此代码,请先检查并重新提交您的版本。

因为苹果宣布iOS应用程序也应该在ipad上正常运行。所以,我们需要确保当我们从相机中捕获照片并从照片库中选择时,我们还需要更新关于
UIImagePickerViewController
的iPad代码。我附上了在iPhone和iPad上都能使用的代码

let actionSheetController: UIAlertController = UIAlertController(title: "Select Photo", message: "", preferredStyle: .actionSheet)

    let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
        print("Cancel")
    }
    actionSheetController.addAction(cancelActionButton)


    let saveActionButton: UIAlertAction = UIAlertAction(title: "Photolibrary", style: .default)
    { action -> Void in

        self.picker.allowsEditing = true
        self.picker.sourceType = .photoLibrary
        self.present(self.picker, animated: true, completion: nil)

    }
    actionSheetController.addAction(saveActionButton)

    let deleteActionButton: UIAlertAction = UIAlertAction(title: "Camera", style: .default)
    { action -> Void in

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)
        {
            self.picker.allowsEditing = true
            self.picker.sourceType = .camera
            self.present(self.picker, animated: true, completion: nil)
        }

    }

    actionSheetController.addAction(deleteActionButton)

    if let popoverController = actionSheetController.popoverPresentationController {

        popoverController.sourceView = self.view
        popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
        popoverController.permittedArrowDirections = []
    }
    self.present(actionSheetController, animated: true, completion: nil)

你收到崩溃日志了吗?你收到了什么错误消息?它在哪一行崩溃?我没有ipad来测试它。苹果在应用程序提交审查时报告了这次崩溃。你为什么不在Xcode中使用iPad模拟器呢?