LoginSignup
17
19

More than 5 years have passed since last update.

iOS8.1ではフォトストリーム上のALAssetをassetForURLでは読み込めない

Posted at

http://stackoverflow.com/questions/26480526/alassetslibrary-assetforurl-always-returning-nil-for-photos-in-my-photo-stream
ここに書いてある内容そのままなのですが、

iOS8.1以前では、

iCloudのフォトストリーム上の画像をALAssetLibraryのassetForURLで読み込むことができましたが、
iOS8.1は、その方法ではnilを返すようになってしまいました。

new_code
[assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
    if (asset)
    {
        // フォトストリーム以外のALAssetを取得成功
    }
    else 
    {
        [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupPhotoStream usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
            [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                if ([result.defaultRepresentation.url isEqual:url])
                    // フォトストリームのALAsset取得成功
                    *stop = YES;
                }
            }];
        } failureBlock:^(NSError *error) {
            // フォトストリームのALAsset取得失敗
        }];
    }
} failureBlock:^(NSError *error) {
    // フォトストリーム以外のALAsset取得失敗
}];

これでたぶんOS依存はなくなったのです。

しかし、ネストが深くなってしまいました。

もっと一発で取得するベターな方法があれば情報共有お願いします。

17
19
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
17
19