Improve access to Photos in your app

RSS for tag

Discuss the WWDC21 session Improve access to Photos in your app.

Posts under wwdc21-10046 tag

5 Posts

Post

Replies

Boosts

Views

Activity

PHPickerViewController causes memory link
I want to pick an image with PHPickerViewController. But this causes to memory link. Can anyone help me with this issue?( I created ImagePickerManager and I'm using it on ViewController below. P.s: I didn't get a leak when writing the same code with UIImagePickerViewController. import Foundation import Photos import PhotosUI class ImagePickerManager: NSObject {   // MARK: Variables   var accessType: PHAccessLevel = .addOnly   var pickerViewController = PHPickerViewController(configuration: PHPickerConfiguration())   //var viewController: UIViewController?   var pickImageCallback : ((UIImage) -> ())?;   // MARK: Init   override init() {     super.init()     setupPhotoPicker()     setupPhotoLibrary(accessType)   } //  convenience init( //    viewController: UIViewController, //    accessType: PHAccessLevel = .addOnly) { //      self.init() // //      self.viewController = viewController //      setupPhotoLibrary(accessType) //      setupPhotoPicker() //    }   // MARK: Setup   private func setupPhotoLibrary(_ accessType: PHAccessLevel) {     self.checkAuthorizationStatusForPhotoLibrary()     self.accessType = accessType   }   private func setupPhotoPicker() {     pickerViewController.delegate = self   }   // MARK: Present PickerController   func presentPHPicker(_ viewContr: UIViewController,_ callback: @escaping ((UIImage) -> ())) {     pickImageCallback = callback    // self.viewController = viewContr     viewContr.present(pickerViewController, animated: true)   }   // MARK: Checking status of Photo library access   func checkAuthorizationStatusForPhotoLibrary() {     switch PHPhotoLibrary.authorizationStatus(for: accessType) {     case .authorized: break     case .notDetermined:       self.requestAuthorizationForPhotoLibrary()     case .denied:       self.showAccessDeniedMessage()     default: return     }   }   // MARK: Request to Access Photo Library   func requestAuthorizationForPhotoLibrary () {     PHPhotoLibrary.requestAuthorization(for: accessType) { status in       switch status {       case .authorized:         print("Access granted")       case .denied: break       case .notDetermined: break       default: return       }     }   }   // MARK: Access Denied to do action   private func showAccessDeniedMessage() {     print("\n ShowAccessDeniedMessage \n")   } } // MARK: - PHPickerViewControllerDelegate extension ImagePickerManager: PHPickerViewControllerDelegate, UINavigationControllerDelegate {   func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {     picker.dismiss(animated: true, completion: nil)     for result in results {       result.itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { (object, error) in         if let image = object as? UIImage { //          DispatchQueue.main.async {             // Use UIImage             self.pickImageCallback?(image) //          }         }       })     }   } } /// -------- ViewController let imageManager = ImagePickerManager()   @objc func pressedButton() {     imageManager.presentPHPicker(self) { image in       print("something...")     }   }
2
0
1.7k
Apr ’22
Allow PHPicker access to original/unadjusted asset
The newish PHPicker is a great way to access the users’ photo library without requiring fill access permissions. However, this is currently no way for accessing the original or unadjusted version of an asset. The preferredAssetRepresentationMode of the PHPickerConfiguration only allows the options automatic, compatible, and current, where current still returns the asset with previous adjustments applied. The option only seems to impact potential asset transcoding. In contrast, when fetching PHAsset data, one can specify the PHImageRequestOptionsVersion unadjusted or original, which give access to the underlying untouched image. It would be great to have these options in the PHPicker interface as well. The alternative would be to load the image through PHAsset via the identifier returned by the picker, but that would require full library access, which I want to avoid. Or is there another way to access the original image without these permissions?
2
0
1k
Oct ’21
trouble enabling two finger gesture to go back to previous page on a webview app
I have enabled the following swipe gesture and it works however with voiceover it doesnt respond and doesnt allow the user to go back with the two finger swipe from left to right Heres the code that i have written so far - import UIKit import WebKit class ViewController: UIViewController { let webView: WKWebView = { let prefs = WKWebpagePreferences() prefs.allowsContentJavaScript = true let configuration = WKWebViewConfiguration() configuration.defaultWebpagePreferences = prefs let webView = WKWebView(frame: .zero, configuration: configuration) return webView }() override func viewDidLoad() { super.viewDidLoad() view.addSubview(webView) guard let url = URL(string: "https://sindhisystems.co.uk") else { return } func goBack(_ sender: Any) { webView.goBack() } webView.load(URLRequest(url: url)) webView.customUserAgent = "iPad/Chrome/SomethingRandom" webView.allowsBackForwardNavigationGestures = true DispatchQueue.main.asyncAfter(deadline: .now()+5) { self.webView.evaluateJavaScript("document.body.innerHTML") { result, error in guard let html = result as? String, error == nil else { return } print(html) } } } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() webView.frame = view.bounds } }
0
0
657
Aug ’21
PHPhotosErrorInvalidState
I updated my MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports, Processor: 3.1 GHz Dual-Core Intel Core i5, Memory 8 GB 2133 MHz LPDDR3) to macOS Big Sur Version 11.5.1 recently. Ever since, my Photos Libraries on External Hard drives cannot be opened. The "PHPhotosErrorInvalidState" message keeps appearing. Even when I tried to create a new library, the same message would appear. HELP!!! I have over 10 years of photos/videos stored on many external hard drives that cannot be accessed now. All of my past few months of works are also stored on these libraries which cannot be opened now. URGENTLY NEED HELP!!!!
1
0
692
Aug ’21
PHPickerViewController causes memory link
I want to pick an image with PHPickerViewController. But this causes to memory link. Can anyone help me with this issue?( I created ImagePickerManager and I'm using it on ViewController below. P.s: I didn't get a leak when writing the same code with UIImagePickerViewController. import Foundation import Photos import PhotosUI class ImagePickerManager: NSObject {   // MARK: Variables   var accessType: PHAccessLevel = .addOnly   var pickerViewController = PHPickerViewController(configuration: PHPickerConfiguration())   //var viewController: UIViewController?   var pickImageCallback : ((UIImage) -> ())?;   // MARK: Init   override init() {     super.init()     setupPhotoPicker()     setupPhotoLibrary(accessType)   } //  convenience init( //    viewController: UIViewController, //    accessType: PHAccessLevel = .addOnly) { //      self.init() // //      self.viewController = viewController //      setupPhotoLibrary(accessType) //      setupPhotoPicker() //    }   // MARK: Setup   private func setupPhotoLibrary(_ accessType: PHAccessLevel) {     self.checkAuthorizationStatusForPhotoLibrary()     self.accessType = accessType   }   private func setupPhotoPicker() {     pickerViewController.delegate = self   }   // MARK: Present PickerController   func presentPHPicker(_ viewContr: UIViewController,_ callback: @escaping ((UIImage) -> ())) {     pickImageCallback = callback    // self.viewController = viewContr     viewContr.present(pickerViewController, animated: true)   }   // MARK: Checking status of Photo library access   func checkAuthorizationStatusForPhotoLibrary() {     switch PHPhotoLibrary.authorizationStatus(for: accessType) {     case .authorized: break     case .notDetermined:       self.requestAuthorizationForPhotoLibrary()     case .denied:       self.showAccessDeniedMessage()     default: return     }   }   // MARK: Request to Access Photo Library   func requestAuthorizationForPhotoLibrary () {     PHPhotoLibrary.requestAuthorization(for: accessType) { status in       switch status {       case .authorized:         print("Access granted")       case .denied: break       case .notDetermined: break       default: return       }     }   }   // MARK: Access Denied to do action   private func showAccessDeniedMessage() {     print("\n ShowAccessDeniedMessage \n")   } } // MARK: - PHPickerViewControllerDelegate extension ImagePickerManager: PHPickerViewControllerDelegate, UINavigationControllerDelegate {   func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {     picker.dismiss(animated: true, completion: nil)     for result in results {       result.itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { (object, error) in         if let image = object as? UIImage { //          DispatchQueue.main.async {             // Use UIImage             self.pickImageCallback?(image) //          }         }       })     }   } } /// -------- ViewController let imageManager = ImagePickerManager()   @objc func pressedButton() {     imageManager.presentPHPicker(self) { image in       print("something...")     }   }
Replies
2
Boosts
0
Views
1.7k
Activity
Apr ’22
customize PHPicker's Navigationbar color in iOS15
I want to change the background color of PHPicker's navigationbar in iOS15. ↓This answer did not work in PHPicker https://developer.apple.com/forums/thread/682420 How to customize?
Replies
3
Boosts
0
Views
3.3k
Activity
Apr ’22
Allow PHPicker access to original/unadjusted asset
The newish PHPicker is a great way to access the users’ photo library without requiring fill access permissions. However, this is currently no way for accessing the original or unadjusted version of an asset. The preferredAssetRepresentationMode of the PHPickerConfiguration only allows the options automatic, compatible, and current, where current still returns the asset with previous adjustments applied. The option only seems to impact potential asset transcoding. In contrast, when fetching PHAsset data, one can specify the PHImageRequestOptionsVersion unadjusted or original, which give access to the underlying untouched image. It would be great to have these options in the PHPicker interface as well. The alternative would be to load the image through PHAsset via the identifier returned by the picker, but that would require full library access, which I want to avoid. Or is there another way to access the original image without these permissions?
Replies
2
Boosts
0
Views
1k
Activity
Oct ’21
trouble enabling two finger gesture to go back to previous page on a webview app
I have enabled the following swipe gesture and it works however with voiceover it doesnt respond and doesnt allow the user to go back with the two finger swipe from left to right Heres the code that i have written so far - import UIKit import WebKit class ViewController: UIViewController { let webView: WKWebView = { let prefs = WKWebpagePreferences() prefs.allowsContentJavaScript = true let configuration = WKWebViewConfiguration() configuration.defaultWebpagePreferences = prefs let webView = WKWebView(frame: .zero, configuration: configuration) return webView }() override func viewDidLoad() { super.viewDidLoad() view.addSubview(webView) guard let url = URL(string: "https://sindhisystems.co.uk") else { return } func goBack(_ sender: Any) { webView.goBack() } webView.load(URLRequest(url: url)) webView.customUserAgent = "iPad/Chrome/SomethingRandom" webView.allowsBackForwardNavigationGestures = true DispatchQueue.main.asyncAfter(deadline: .now()+5) { self.webView.evaluateJavaScript("document.body.innerHTML") { result, error in guard let html = result as? String, error == nil else { return } print(html) } } } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() webView.frame = view.bounds } }
Replies
0
Boosts
0
Views
657
Activity
Aug ’21
PHPhotosErrorInvalidState
I updated my MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports, Processor: 3.1 GHz Dual-Core Intel Core i5, Memory 8 GB 2133 MHz LPDDR3) to macOS Big Sur Version 11.5.1 recently. Ever since, my Photos Libraries on External Hard drives cannot be opened. The "PHPhotosErrorInvalidState" message keeps appearing. Even when I tried to create a new library, the same message would appear. HELP!!! I have over 10 years of photos/videos stored on many external hard drives that cannot be accessed now. All of my past few months of works are also stored on these libraries which cannot be opened now. URGENTLY NEED HELP!!!!
Replies
1
Boosts
0
Views
692
Activity
Aug ’21