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

7 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
PHPicker: handle missing internet connection
We have a lot of users reporting to us that they can't load images into our app. They just "see the spinner spin indefinitely". We now think we found the reason why: When trying to load an asset via the PHPickerViewController that is not downloaded yet without an active internet connection, the loadFileRepresentationmethod of the item provider will just stall without reporting any progress or error. The timeout for this seems to be 5 minutes, which is way too high. The same is true if the user disabled cellular data for Photos and attempts to load a cloud asset while not on wifi. Steps to reproduce: have a photo in iCloud that is not yet downloaded activate Airplane Mode open the picker and select that photo see when loadFileRepresentation will return Since it is clear that without an internet connection the asset can’t be downloaded, I would hope to be informed via a delegate method of the picker or the loadFileRepresentation callback that there was an error trying to load the asset. (FB9221090) Right now we are attempting to solve this by adding an extra timer and a network check. But this will not catch the "no cellular data allowed"-case. Please consider some callback mechanism to the API so we can inform the user what the problem might be. Thanks!
1
0
1.4k
Jul ’21
PHPicker: add cloud indicator
Adding to my previous post, it would be great if the PHPicker would display if an asset is only available in the cloud and would need to be downloaded first. This might give the user a hint that the loading process might take longer and might cause network traffic. Right now, it's unclear for the user (and for us developers) that an asset needs to be downloaded. A small cloud icon would help a lot, I think. (FB9221095) Thanks for considering!
1
0
877
Jun ’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
PHPicker: handle missing internet connection
We have a lot of users reporting to us that they can't load images into our app. They just "see the spinner spin indefinitely". We now think we found the reason why: When trying to load an asset via the PHPickerViewController that is not downloaded yet without an active internet connection, the loadFileRepresentationmethod of the item provider will just stall without reporting any progress or error. The timeout for this seems to be 5 minutes, which is way too high. The same is true if the user disabled cellular data for Photos and attempts to load a cloud asset while not on wifi. Steps to reproduce: have a photo in iCloud that is not yet downloaded activate Airplane Mode open the picker and select that photo see when loadFileRepresentation will return Since it is clear that without an internet connection the asset can’t be downloaded, I would hope to be informed via a delegate method of the picker or the loadFileRepresentation callback that there was an error trying to load the asset. (FB9221090) Right now we are attempting to solve this by adding an extra timer and a network check. But this will not catch the "no cellular data allowed"-case. Please consider some callback mechanism to the API so we can inform the user what the problem might be. Thanks!
Replies
1
Boosts
0
Views
1.4k
Activity
Jul ’21
PHPicker: add cloud indicator
Adding to my previous post, it would be great if the PHPicker would display if an asset is only available in the cloud and would need to be downloaded first. This might give the user a hint that the loading process might take longer and might cause network traffic. Right now, it's unclear for the user (and for us developers) that an asset needs to be downloaded. A small cloud icon would help a lot, I think. (FB9221095) Thanks for considering!
Replies
1
Boosts
0
Views
877
Activity
Jun ’21