我正在創建一個應用程序,捕獲照片並根據照片捕獲時的陀螺儀數據重新定向。在拍攝照片的確切時刻捕獲陀螺儀數據
我創建功能來捕捉與手機的陀螺儀數據:
startUpdates()
,並停止在獲取數據:
stopUpdates()
我嘗試添加該進的UIImagePickerController:
if UIImagePickerController.isSourceTypeAvailable(.camera) {
guard ptInitials.text != "" else {
missingIdentifier(text: "Please add an identifier prior to taking a photo")
return}
startUpdates()
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = false
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraCaptureMode = .photo
imagePicker.modalPresentationStyle = .fullScreen
present(imagePicker,
animated: true,
completion: nil)
}
這會在圖像捕捉過程開始時啓動陀螺儀捕捉。
我把它傳遞給一個可選的double,livePhotoAxis:Double?,同時它正在測量「startUpdates()」函數內的陀螺儀數據。
當我拍攝照片時,我試圖讓它「停止」捕獲數據,因此最後一次已知的陀螺儀數據將保存在我的變量中,並能夠傳遞到其他函數中;
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
stopUpdates()
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
saveImageToDocuments(image: chosenImage, fileNameWithExtension: "image.jpg")
dismiss(animated: true, completion: nil
)
}
然而,問題是,stopUpdates()方法不叫,直到用戶「確認」他們喜歡自己的搶購照片(VS奪回它)之後。
從我讀過的,有一個私人API與uiImagePickerControllerUserDidCaptureItem捕捉照片拍攝的確切時刻。我可以使用NSNotification來嘗試找到並在實際拍攝照片後調用StopUpdates()。
這是否正確,這是一個私人API?我可以用它來捕捉這一刻,否則我的應用程序會被拒絕?
同樣,有沒有更好的方式來關閉我的陀螺儀更新在拍照的確切時刻?
謝謝!