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 ごとに異なるメモリ アドレスを示します。
UIDocument サブクラスに NSLog がありますが、呼び出されません。リリースしていないことがどこに保持されているのかわかりません。このクエリは、クラウド データを同期するたびに実行されます。これはかなり定期的に行われます。データは正しく同期されます。
デバッグに何も表示されず、アプリが単にダッシュボードに閉じられるという奇妙なクラッシュが発生しています (以前の経験から、アプリがメモリを消費しすぎて終了することがよくあります)。
私のUIDocumentが漏れていると思います.この仮定で正しいでしょうか.iCloudと格闘したのはこれが初めてなので、いくつかのことでまだ暗闇の中にいます.
私のサブクラスには次のプロパティがあります。
@property (copy, nonatomic) NSData *infoData;
@property (copy, nonatomic) NSMutableArray *firstArray;
@property (copy, nonatomic) NSMutableArray *secondArray;
@property (copy, nonatomic) NSMutableArray *thirdArray;
私はARCを使用していません。