【问题标题】:How to handle the Don't Allow option in permission dialogue in Swift如何在 Swift 的权限对话框中处理不允许选项
【发布时间】:2015-07-30 14:34:38
【问题描述】:

我正在开发一个使用 PHAssets 类方法访问用户照片库的应用程序。一旦用户选择他的选项允许或不允许,如何能够再次“访问您的照片”权限对话框。如果用户选择允许我们如何同时获取数据。 其次,我们如何处理 Swift 中的“不允许”选项。 代码如下:

覆盖 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



}

【问题讨论】:

    标签: swift permissions dialog alert photos


    【解决方案1】:
    1. 您无法再次显示“访问您的照片”权限对话框。显示后,只能在 iOS 设置中更改。
    2. 允许选项:使用PHImageManager.defaultManager().requestImageForAsset,您可以立即访问照片。
    3. 不允许选项:如果用户不允许,您需要让他在设置的 iOS 中允许:UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
    4. 查看权限状态:Determine if the access to photo library is set or not - PHPhotoLibrary (iOS 8)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    相关资源
    最近更新 更多