我正在处理图像到 iCloud 存储。使用 this link我正在实现的示例代码。但在这里我使用 GridView 来显示图像。对于 GridView ,我正在使用 AQGridView
示例。现在我在实现时遇到了一些问题。
我的项目在本地存储中运行良好,但在 iCloud
存储中无法运行。虽然将图像添加到 GridView 时只添加了一个 View ,但完成后它从 View 中删除了,而且我没有得到 CloudURL
。
这里是一些主要代码
- (void)processiCloudFiles:(NSNotification *)notification {
// Always disable updates while processing results
[_query disableUpdates];
[_iCloudURLs removeAllObjects];
// The query reports all files found, every time.
NSArray * queryResults = [_query results];
for (NSMetadataItem * result in queryResults) {
NSURL * fileURL = [result valueForAttribute:NSMetadataItemURLKey];
NSNumber * aBool = nil;
// Don't include hidden files
[fileURL getResourceValue:&aBool forKey:NSURLIsHiddenKey error:nil];
if (aBool && ![aBool boolValue]) {
[_iCloudURLs addObject:fileURL];
NSLog(@"%@",_iCloudURLs);
}
}
NSLog(@"Found %d iCloud files.", _iCloudURLs.count);
_iCloudURLsReady = YES;
if ([self iCloudOn]) {
NSLog(@"%d",_objects.count);
// Remove deleted files
// Iterate backwards because we need to remove items form the array
for (int i = _objects.count -1; i >= 0; --i) {
PTKEntry * entry = [_objects objectAtIndex:i];
if (![_iCloudURLs containsObject:entry.fileURL]) {
[self removeEntryWithURL:entry.fileURL];
}
}
NSLog(@"%@",_iCloudURLs);
// Add new files
for (NSURL * fileURL in _iCloudURLs) {
[self loadDocAtURL:fileURL];
}
self.navigationItem.rightBarButtonItem.enabled = YES;
}
if (_moveLocalToiCloud) {
_moveLocalToiCloud = NO;
[self localToiCloudImpl];
}
else if (_copyiCloudToLocal) {
_copyiCloudToLocal = NO;
[self iCloudToLocalImpl];
}
[_query enableUpdates];
}
我还展示了我的应用程序的控制台流程,请帮助我
2013-02-19 13:29:26.159 XXXX[337:907] iCloud available at: file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXXX~com~XXXX~XXXX/
2013-02-19 13:29:32.847 XXXX[337:907] No longer watching iCloud dir...
2013-02-19 13:29:32.849 XXXX[337:907] Starting to watch iCloud dir...
2013-02-19 13:29:33.002 XXXX[337:907] Found 0 iCloud files.
2013-02-19 13:29:33.004 XXXX[337:907] local => iCloud impl
2013-02-19 13:29:38.697 XXXX[337:907] Want to create file at file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXX~com~XXXX~XXXX/Documents/iBoast_Art_Soodu.ibt
2013-02-19 13:29:38.781 XXXX[337:907] File created at file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXX~com~XXXX~XXXX/Documents/iBoast_Art_Soodu.ibt
2013-02-19 13:29:38.790 XXXX[337:907] load table
2013-02-19 13:30:38.563 XXXX[337:907] button index: 1
2013-02-19 13:30:41.595 XXXX[337:907] iCloud available at: file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXX~com~XXXX~XXXX/
2013-02-19 13:30:41.607 XXXX[337:907] No longer watching iCloud dir...
2013-02-19 13:30:41.612 XXXX[337:907] Starting to watch iCloud dir...
2013-02-19 13:30:41.780 XXXX[337:907] Success to close file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXX~com~XXXX~XXXX/Documents/iBoast_Art_Soodu.ibt
2013-02-19 13:30:41.790 XXXX[337:907] load table
2013-02-19 13:30:42.011 XXXX[337:907] Found 0 iCloud files.
最佳答案
这个我没有权威的答案,但我肯定怀疑这是时间问题。我希望看到一些委托(delegate)操作继续进行,以了解 iCloud 项目何时上传。
我还会稍微改进一下您的日志记录。线路
NSLog(@"%@",_iCloudURLs);
应该有更好的格式。没有这个,我不能确定,但看起来这条线永远不会到达。
关于iphone - 无法使用 iCloud 存储在 GridView 中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14956212/