I'm attempting to control flow for an application that needs access to the device camera. The idea is to check the setting for camera access and if camera access is not allowed, give the user the opportunity to go directly to the settings for the app. Then once the switch for camera is changed (or not) return the user to the app.
The following code seems to do that when the app is run from the device. However, if the device is tethered and the app starts from Xcode, the instant the switch is touched, the App crashes. There is no information written to the console - just the dreaded highlight of the AppDelegate first line. Obviously, I don't trust that it is actually "working" on the device.
Any help would be appreciated.
Xcode 7.2.1 IOS 9.2.1
var userOkForCamera : Bool = false
@IBAction func takeInvItemPhoto(sender: UIButton) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
        if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) ==  AVAuthorizationStatus.Authorized {
            // Already Authorized
            // This seems to work ok when the use auth switch is On
            userOkForCamera = true
            let picker = UIImagePickerController()
            picker.delegate = self
            picker.sourceType = UIImagePickerControllerSourceType.Camera
            picker.mediaTypes = [kUTTypeImage as String]
            picker.allowsEditing = false
            presentViewController(picker, animated: true, completion: nil)
        } else {
            userOkForCamera = false
        }//if auth status else
        if userOkForCamera == false {
            showCameraAcessDeniedAlert()
            return
        }// if user ok false
    } else {//if camera
        let ac = UIAlertController(title: "Source Not Available", message: "The camera is not available.", preferredStyle: .Alert)
                ac.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
                presentViewController(ac, animated: true, completion: nil)
    }//if camera else
}//takeInvItemPhoto
    func showCameraAcessDeniedAlert() {
    let alertController = UIAlertController(title: "Uh-ooh!",
        message: "It looks like camera permission is not authorized. Please enable it in Settings to continue.",
        preferredStyle: .Alert)
    let settingsAction = UIAlertAction(title: "Settings", style: .Default) { (alertAction) in
        if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {
            UIApplication.sharedApplication().openURL(appSettings)
        }//if let
    }//settings action block
    alertController.addAction(settingsAction)
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    alertController.addAction(cancelAction)
    presentViewController(alertController, animated: true, completion: nil)
}//showCameraAcessDeniedAlert
