0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[PHImageManager] iOS12以前とiOS13以降の挙動の変化について

Last updated at Posted at 2019-10-19

私の製作しているアプリはPhotosのPHImageManagerを使っています。
iOS13で正常に動作しなくなり、PHImageManager.requestImage~の挙動を確認したところ、オリジナルのサイズより大きいサイズは返してくれないことがわかりました。

    //written on '19.10.17
    func testPHImageManager() {
        let imgManager = PHImageManager.default()

        //option setting
    	let  op = PHImageRequestOptions()
        op.isSynchronous = true//MARK: false で順番が入れ替わるか
        op.resizeMode = .exact
        op.deliveryMode = .highQualityFormat

        let asset = testAssets[0]
        let w = CGFloat(asset.pixelWidth)
        let h = CGFloat(asset.pixelHeight)

		let originalSize = CGSize(width: w, height: h)
        
        for i in 0..<20 {
            let targetSize = CGSize(width: w*i.cgfloat * 0.5 , height: h*i.cgfloat * 0.5)
            
            //targetSize in pixel
            imgManager.requestImage(for: asset, targetSize:targetSize , contentMode: PHImageContentMode.aspectFill, options: op){
                img,info in

                guard var tmpImg = img else{
                    return
                }

                print("-------------")
                print("original: \(originalSize)")
                print("targetSize: \(targetSize)")
                print("actualSize: \(img!.size)")
                print("-------------")
            }
        }
    }

    //written on '19.10.17
    private func moveToPickerViewController() {
        let configuration = DKImageGroupDataManagerConfiguration()
        let assetFetchOptions = PHFetchOptions()
        assetFetchOptions.predicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.image.rawValue)
        configuration.assetFetchOptions = assetFetchOptions
        configuration.assetGroupTypes = [.smartAlbumUserLibrary]

        let groupDataManager = DKImageGroupDataManager(configuration: configuration)
        
        let pickerController = DKImagePickerController(groupDataManager: groupDataManager)
        pickerController.assetType = .allPhotos
        pickerController.sourceType = .photo
        pickerController.showsEmptyAlbums = false
        
        pickerController.didSelectAssets = { [unowned self] (assets:[DKAsset]) in
            self.testAssets = assets.map() {
                return ($0.originalAsset!)
            }
        }
        
        self.modalPresentationStyle = .pageSheet
        self.present(pickerController, animated: true, completion: nil)
    }

出力

-------------
original: (750.0, 1334.0)
targetSize: (375.0, 667.0)
actualSize: (375.0, 667.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (750.0, 1334.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (1125.0, 2001.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (1500.0, 2668.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (1875.0, 3335.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (2250.0, 4002.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (2625.0, 4669.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (3000.0, 5336.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (3375.0, 6003.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (3750.0, 6670.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (4125.0, 7337.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (4500.0, 8004.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (4875.0, 8671.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (5250.0, 9338.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (5625.0, 10005.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (6000.0, 10672.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (6375.0, 11339.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (6750.0, 12006.0)
actualSize: (750.0, 1334.0)
-------------
-------------
original: (750.0, 1334.0)
targetSize: (7125.0, 12673.0)
actualSize: (750.0, 1334.0)
-------------

cf. DKImagePickerController
https://github.com/zhangao0086/DKImagePickerController

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?