Я пытаюсь получить всплывающее предупреждение для сохранения видео из триггера из CoreMotion
Данные.
У меня проблемы с сохранением видео из запроса Да.
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = true
imagePicker.delegate = self
imagePicker.sourceType = .camera;
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.allowsEditing = false
imagePicker.showsCameraControls = false
imagePicker.perform(#selector(UIImagePickerController.startVideoCapture), with: nil, afterDelay: 1)
// shows camera onto screen
self.present(imagePicker, animated: true)
do {
motion.accelerometerUpdateInterval = 0.25
motion.startAccelerometerUpdates(to: OperationQueue.current!) { (data, error) in
print(data as Any)
if let trueData = data {
//self.view.reloadInputViews()
let x = trueData.acceleration.x
let y = trueData.acceleration.y
let z = trueData.acceleration.z
let totalAcceleration = calculateMagnitude (no1:Float (x), no2: Float (y),no3: Float (z))
if (Float(totalAcceleration) > 2.00){
self.dismiss(animated: true, completion : nil)
let alert = UIAlertController (title: "Sudden acceleration detected", message: "Are you in an accident?", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertAction.Style.default, handler: {(action:UIAlertAction!) in
print("User has selected Yes")//Here is where I want to save the video
}))
alert.addAction(UIAlertAction(title: "No", style: UIAlertAction.Style.default, handler: {(action:UIAlertAction!) in
print("User has selected No")
imagePicker.perform(#selector(UIImagePickerController.startVideoCapture), with: nil, afterDelay: 1)
// shows camera onto screen
self.present(imagePicker, animated: true)
}))
}
Все ответы, которые я нашел, на самом деле мне совсем не помогли: [
TLDR: Запустить приложение.Телефон записывает, что перед ним.Изменение в CoreMotion
данных.Да или Нет Подсказка появляется.Нет продолжает запись.Да сохраняет видео.