Swift3にてQRコードを読み取るアプリの作成を行っております。
iPoneのバックカメラを使用する際に、
初回起動ではswift側の処理でアラートが表示されていますが、
2回目以降の起動時にプライバシー設定において許可がない時にアラートを表示し、設定に遷移するプログラムを作成したいと考えています。
以下のソースコードを記載しましたが、
addActionを設定の箇所を丸々飛ばしており、アラートが表示されません。
エラーメッセージは表示されておらず、コンパイルも問題なく行われています。
アラートを表示させるにはどうすればよいでしょうか。
----追記
カメラのプライバシー設定の確認を行うcase文では問題なく判定を行っており、プライバシー設定の許可がない場合に到達する.deniedに到達しております。
###該当のソースコード
//カメラの設定+リスナ(delegate)の設定 sessionQueue.async { let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) switch (status) { case .authorized: break; case .restricted: self.showCamereAlert() case .notDetermined: break case .denied: print("case:許可なし 到達") self.showCamereAlert() } let devices = AVCaptureDevice.devices() guard let device = devices?.first as? AVCaptureDevice else { assertionFailure("Not found camera") return } do { let input = try AVCaptureDeviceInput(device: device) self.session.addInput(input) } catch let error as NSError { print("エラー発生") assertionFailure(error.debugDescription) return } let output = AVCaptureMetadataOutput() output.setMetadataObjectsDelegate(self, queue: DispatchQueue(label: "meta queue", attributes: [])) self.session.addOutput(output) output.metadataObjectTypes = self.targetTypes } } private func showCamereAlert() { let alert = UIAlertController( title: "カメラアクセス許可なし", message: "カメラへのアクセス許可がありません。設定よりアクセスを許可してください。", preferredStyle: .alert) print("URL設定前") alert.addAction(UIAlertAction(title :"設定", style: .default, handler: {(action: UIAlertAction!) ->Void in if let url = NSURL(string: "App-Prefs:root=Privacy") { print("★★★★★★★★★★★★★★★★★") UIApplication.shared.open(url as URL,options: [:],completionHandler: nil) print("URL設定完了")}else{ print("アラート失敗") } } )) self.present(alert, animated: true, completion: nil) }
回答1件
あなたの回答
tips
プレビュー