我有一个问题,我似乎在哪里可以不要的dealloc UIDocument(iCloud中使用)
运行NSMetaDataQuery之后寻找文档如下..
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
_query = query;
[query setSearchScopes:[NSArray arrayWithObject:
NSMetadataQueryUbiquitousDocumentsScope]];
NSPredicate *pred = [NSPredicate predicateWithFormat:
@"%K == %@", NSMetadataItemFSNameKey, kFILENAME];
[query setPredicate:pred];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidFinishGathering:)
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
[query startQuery];
我处理我的查询
- (void)queryDidFinishGathering:(NSNotification *)notification {
NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
_query = nil;
[self loadData:query];
}
然后加载或创建一个新文档。
- (void)loadData:(NSMetadataQuery *)query {
if ([query resultCount] == 1) {
NSMetadataItem *item = [query resultAtIndex:0];
NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
MyDocument *doc = [[[MyDocument alloc] initWithFileURL:url] autorelease];
[doc openWithCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"iCloud document opened %@", doc);
[doc updateChangeCount:UIDocumentChangeDone];
} else {
NSLog(@"failed opening document from iCloud");
}
}];
} else {
NSURL *ubiq = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil];
NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:
@"Documents"] URLByAppendingPathComponent:kFILENAME];
MyDocument *doc = [[[MyDocument alloc] initWithFileURL:ubiquitousPackage] autorelease];
[doc saveToURL:[doc fileURL]
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success) {
if (success) {
[doc openWithCompletionHandler:^(BOOL success) {
NSLog(@"new document opened from iCloud");
[doc updateChangeCount:UIDocumentChangeDone];
}];
}
}];
}
}
该NSLog(@"iCloud document opened %@", doc);
示出了一个不同的存储器地址为每个UIDocument。
我有一个NSLog的在我的UIDocument子类,它永远不会被调用。 我无法看到它被保留,我不释放它在哪里。 此查询跑了,每当我想要同步我的云数据,这相当定期发生。 该数据能够正常同步。
我遇到奇怪的崩溃在我的应用程序将简单地关闭到仪表板,什么也没有在调试(从以前的经验,我知道这一点经常被应用程序花费太多的内存和被终止。)
我认为我的UIDocument漏水,我会在这个假设是正确的,这是我第一次与iCloud的搏斗所以我仍然在黑暗中过了一些东西。
我的子类具有以下特性:
@property (copy, nonatomic) NSData *infoData;
@property (copy, nonatomic) NSMutableArray *firstArray;
@property (copy, nonatomic) NSMutableArray *secondArray;
@property (copy, nonatomic) NSMutableArray *thirdArray;
我不使用ARC。