Photos Framework requestImageDataForAsset occasionally fails

前端 未结 4 1841
不思量自难忘°
不思量自难忘° 2020-12-24 14:54

I\'m using the photos framework on iOS8.1 and requesting the image data for the asset using requestImageDataForAsset... Most of the time it works and I get the image data an

4条回答
  •  攒了一身酷
    2020-12-24 15:27

    I had a problem with similar symptoms where requestImageDataForAsset returned nil image data but was also accompanied by a console error message like this:

    [Generic] Failed to load image data for asset 87CCAFDC-A0E3-4AC9-AD1C-3F57B897A52E/L0/001 mediaType=1/0, sourceType=2, (113x124), creationDate=2015-06-29 04:56:34 +0000, location=0, hidden=0, favorite=0 with format 9999

    In my case, the problem suddenly started happening on a specific device only with assets in iCloud shared albums after upgrading from iOS 10.x to 11.0.3, and since then through to 11.2.5. Thinking that maybe requestImageDataForAsset was trying to use files locally cached in /var/mobile/Media/PhotoData/PhotoCloudSharingData/ (from the info dictionary's PHImageFileURLKey key) and that the cache may be corrupt I thought about how to clear that cache.

    Toggling the 'iCloud Photo Sharing' switch in iOS' Settings -> Accounts & Passwords -> iCloud -> Photos seems to have done the trick. requestImageDataForAsset is now working for those previously failing assets.

    Update 9th March 2018

    I can reproduce this problem now. It seems to occur after restoring a backup from iTunes:

    1. Use the iOS app and retrieve photos from an iCloud shared album.
    2. Backup the iOS device using iTunes.
    3. Restore the backup using iTunes.
    4. Using the app again to retrieve the same photos from the iCloud shared album now fails with the above console message.

    Toggling the 'iCloud Photo Sharing' switch fixes it still. Presumably the restore process somehow corrupts some cache. I've reported it as Bug 38290463 to Apple.

提交回复
热议问题