0

I was working on a app which access the user photo library using the PHAssets class method. How would be able to “Access your photos” permission dialog again once the user selects his options Allow or Don't Allow. If the user selects Allow how could we fetch the data at the same time. Second how can we handle Don't Allow option in Swift. Here is the code:

override func viewDidLoad() { super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.

        let images = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: nil)
        let targetSize: CGSize = CGSize(width: 350, height: 480)//  target size
        let contentMode: PHImageContentMode = PHImageContentMode.AspectFill //  content mode
        images.enumerateObjectsUsingBlock {
        object, index, stop in

        let options = PHImageRequestOptions()
        options.synchronous = true
        options.deliveryMode = .HighQualityFormat


            PHImageManager.defaultManager().requestImageForAsset(object as! PHAsset, targetSize: targetSize, contentMode: contentMode, options: options) {
                image, info in
                self.myCol.append(image)

            }
        }
       ImageCol.store = myCol



}

1 Answers1

0
  1. You can't show “Access your photos” permission dialog again. After showed, it only be changed at iOS Settings.
  2. Allow option: With PHImageManager.defaultManager().requestImageForAsset you can access photos immediately.
  3. Don't Allow option: If user didnt allow, you need to ask him to allow at settings's iOS: UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
  4. Check permission status: Determine if the access to photo library is set or not - PHPhotoLibrary (iOS 8)
Community
  • 1
  • 1
Klevison
  • 3,342
  • 2
  • 19
  • 32
  • Actually I'm not able to handle the selected option. Like the user selected Ok so my code should execute and populate the array. But it populates the data upon app restart not at the same time – vishal thakur Jul 31 '15 at 13:16
  • Try to follow: https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html#//apple_ref/doc/uid/TP40014575-Intro-DontLinkElementID_2 – Klevison Jul 31 '15 at 13:53