Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6482: Put callback from photo permissions onto main thread #6556

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2144,22 +2144,26 @@ extension BrowserViewController: ContextMenuHelperDelegate {
let photoAuthorizeStatus = PHPhotoLibrary.authorizationStatus()
let saveImageAction = UIAlertAction(title: Strings.ContextMenuSaveImage, style: .default) { _ in
let handlePhotoLibraryAuthorized = {
self.getImageData(url) { data in
PHPhotoLibrary.shared().performChanges({
PHAssetCreationRequest.forAsset().addResource(with: .photo, data: data, options: nil)
})
DispatchQueue.main.async {
self.getImageData(url) { data in
PHPhotoLibrary.shared().performChanges({
PHAssetCreationRequest.forAsset().addResource(with: .photo, data: data, options: nil)
})
}
}
}

let handlePhotoLibraryDenied = {
let accessDenied = UIAlertController(title: Strings.PhotoLibraryFirefoxWouldLikeAccessTitle, message: Strings.PhotoLibraryFirefoxWouldLikeAccessMessage, preferredStyle: .alert)
let dismissAction = UIAlertAction(title: Strings.CancelString, style: .default, handler: nil)
accessDenied.addAction(dismissAction)
let settingsAction = UIAlertAction(title: Strings.OpenSettingsString, style: .default ) { _ in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:])
DispatchQueue.main.async {
let accessDenied = UIAlertController(title: Strings.PhotoLibraryFirefoxWouldLikeAccessTitle, message: Strings.PhotoLibraryFirefoxWouldLikeAccessMessage, preferredStyle: .alert)
let dismissAction = UIAlertAction(title: Strings.CancelString, style: .default, handler: nil)
accessDenied.addAction(dismissAction)
let settingsAction = UIAlertAction(title: Strings.OpenSettingsString, style: .default ) { _ in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:])
}
accessDenied.addAction(settingsAction)
self.present(accessDenied, animated: true, completion: nil)
}
accessDenied.addAction(settingsAction)
self.present(accessDenied, animated: true, completion: nil)
}

if photoAuthorizeStatus == .notDetermined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,26 @@ extension BrowserViewController: WKUIDelegate {
let photoAuthorizeStatus = PHPhotoLibrary.authorizationStatus()
actions.append(UIAction(title: Strings.ContextMenuSaveImage, identifier: UIAction.Identifier("linkContextMenu.saveImage")) { _ in
let handlePhotoLibraryAuthorized = {
getImageData(url) { data in
PHPhotoLibrary.shared().performChanges({
PHAssetCreationRequest.forAsset().addResource(with: .photo, data: data, options: nil)
})
DispatchQueue.main.async {
getImageData(url) { data in
PHPhotoLibrary.shared().performChanges({
PHAssetCreationRequest.forAsset().addResource(with: .photo, data: data, options: nil)
})
}
}
}

let handlePhotoLibraryDenied = {
let accessDenied = UIAlertController(title: Strings.PhotoLibraryFirefoxWouldLikeAccessTitle, message: Strings.PhotoLibraryFirefoxWouldLikeAccessMessage, preferredStyle: .alert)
let dismissAction = UIAlertAction(title: Strings.CancelString, style: .default, handler: nil)
accessDenied.addAction(dismissAction)
let settingsAction = UIAlertAction(title: Strings.OpenSettingsString, style: .default ) { _ in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:])
DispatchQueue.main.async {
let accessDenied = UIAlertController(title: Strings.PhotoLibraryFirefoxWouldLikeAccessTitle, message: Strings.PhotoLibraryFirefoxWouldLikeAccessMessage, preferredStyle: .alert)
let dismissAction = UIAlertAction(title: Strings.CancelString, style: .default, handler: nil)
accessDenied.addAction(dismissAction)
let settingsAction = UIAlertAction(title: Strings.OpenSettingsString, style: .default ) { _ in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:])
}
accessDenied.addAction(settingsAction)
self.present(accessDenied, animated: true, completion: nil)
}
accessDenied.addAction(settingsAction)
self.present(accessDenied, animated: true, completion: nil)
}

if photoAuthorizeStatus == .notDetermined {
Expand Down