iPhone 5s
Xcode8
Swift3.0
ios 最新
Swiftでボタンを押したら
iPhoneに装備しているライトをオンにするコードを書いているのですが
どうもうまくいきません。
まずは、コードを見て頂きたいのですが
```Swift
func Grid(sender: UIButton){
let aaa = AVCaptureDevice() if (aaa.hasTorch){ if (aaa.isTorchAvailable){ do{ try aaa.lockForConfiguration() if (aaa.isTorchActive){ aaa.torchMode = AVCaptureTorchMode.off } else { aaa.torchMode = AVCaptureTorchMode.on } aaa.unlockForConfiguration() } catch{ let alertController = UIAlertController(title: "Cheak", message: "ERROR !!", preferredStyle: .alert) let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertController.addAction(defaultAction) present(alertController, animated: true, completion: nil) } } else { let alertController = UIAlertController(title: "Cheak", message: "This iPhone is not use Torch !!", preferredStyle: .alert) let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertController.addAction(defaultAction) present(alertController, animated: true, completion: nil) } } else { let alertController = UIAlertController(title: "Cheak", message: "This iPhone is not Torch !!", preferredStyle: .alert) let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertController.addAction(defaultAction) present(alertController, animated: true, completion: nil) } }
この部分なのですが AVFoundationのAVCaptureDeviceクラスを使っております。 そして、このGridという関数ですが こちらは、ボタンの関数となっていましてaddSubviewで追加したものになります。 こちらのGridというボタンを押した時にクラッシュしてしまいます。 きちんとエラー処理もしているはずなのですが 何が原因なのでしょうか? 詳しい方ご教示して頂ければと思います。 よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/16 13:23