I created UIActivityViewController
and check which share type is select. I need to save in my photo library and I check .saveToCameraRoll
. If I don't call PHPhotoLibrary.requestAuthorization
in the activityVC.completionWithItemsHandler
then it always returns status like .notDetermined
and shows permission request once. When I call PHPhotoLibrary.requestAuthorization
in the caomplitionHandler it shows permission alert twice and when I allow access in the second alert I can check status as expected.
My code:
let sourceRect = rect ?? CGRect(x: frame.minX, y: frame.maxY - 1, width: frame.width, height: 1)
activityVC.modalPresentationStyle = .popover
activityVC.popoverPresentationController?.sourceRect = sourceRect
activityVC.popoverPresentationController?.sourceView = viewController?.view
activityVC.completionWithItemsHandler = { activity, success, items, error in
guard activity == .saveToCameraRoll else { return }
PHPhotoLibrary.requestAuthorization({ _ in
if PHPhotoLibrary.authorizationStatus() != .authorized {
//here I show alert
}
})
}
viewController?.present(activityVC, animated: true, completion: nil)```