简体   繁体   English

PHAsset Null 但本地标识符有效

[英]PHAsset Null but local identifier is valid

I am trying to load an asset from a local identifier.我正在尝试从本地标识符加载资产。 The local identifier seems to be correct but the asset is null and I can't figure out why.本地标识符似乎是正确的,但资产为空,我不知道为什么。 I have a similar code in another part of my app that works fine.我的应用程序的另一部分有一个类似的代码,可以正常工作。

Queue *queue = [NSEntityDescription insertNewObjectForEntityForName:@"Queue" inManagedObjectContext:self.context];

for (int reyrt = 0; reyrt < self.storeGIF.count; reyrt++) {
    queue.queuetextimagePath = [self.storeGIF objectAtIndex:reyrt];

}


__block float fileSize;
NSArray *identifiers = @[queue.queuetextimagePath];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:identifiers options:nil];
PHAsset *asset  = [assetsFetchResult firstObject];

NSLog (@"identifiers: %@", identifiers);
NSLog (@"assetsFetchResult: %@", assetsFetchResult);
NSLog (@"asset: %@", asset);
    if (!asset) {
        NSLog(@"can't retrieve PHAsset from localIdentifier:%@",identifiers);
    }

Here is the NSLog file result when using the above code.这是使用上述代码时的 NSLog 文件结果。

019-07-19 09:26:36.366739-0400 myApp[1440:328144] identifiers: (
"857AC3DA-C047-4D88-911B-C5FE227E2B96/L0/001"
)

2019-07-19 09:26:36.366945-0400 myApp[1440:328144] assetsFetchResult PHFetchResult: 0x281129900 count=0

2019-07-19 09:26:36.366982-0400 myApp[1440:328144] asset: (null)

2019-07-19 09:26:36.367061-0400 myApp[1440:328144] can't retrieve PHAsset from localIdentifier:(
"857AC3DA-C047-4D88-911B-C5FE227E2B96/L0/001"
)

The problem is that you should drop /L0/001 part before requesting the object.问题是您应该在请求对象之前删除/L0/001部分。 I don't understand why uuid strings contain these suffixes, but it works if you drop it and use only normal UUID part.我不明白为什么 uuid 字符串包含这些后缀,但是如果您删除它并仅使用普通的UUID部分,它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM