コアデータベースを使用しています。IOS6で動作していますが、IOS5でテストしようとすると何も起こりません。私がしていることを説明させてください。
まず、viewWillAppearでこれを行います。
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"view appeared");
[super viewWillAppear:animated];
if (!self.genkDatabase) {
NSLog(@"comes to here");
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"Default appGenk Database2"];
// url is now "<Documents Directory>/Default Photo Database"
self.genkDatabase = [[UIManagedDocument alloc] initWithFileURL:url]; // setter will create this for us on disk
NSLog(@"database created on disk");
}
}
次に、UseDocumentメソッドに入ります。
- (void)useDocument
{
NSLog(@"Comses in the use document");
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.genkDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.genkDatabase saveToURL:self.genkDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
NSLog(@"create");
[self setupFetchedResultsController];
[self fetchGenkDataIntoDocument:self.genkDatabase];
}];
} else if (self.genkDatabase.documentState == UIDocumentStateClosed) {
NSLog(@"closed news");
// exists on disk, but we need to open it
[self.genkDatabase openWithCompletionHandler:^(BOOL success) {
[self setupFetchedResultsController];
}];
} else if (self.genkDatabase.documentState == UIDocumentStateNormal) {
NSLog(@"normal");
// already open and ready to use
[self setupFetchedResultsController];
}
}
そして最後に、それはsetDatabaseメソッドに入ります。
- (void)setGenkDatabase:(UIManagedDocument *)genkDatabase
{
if (_genkDatabase != genkDatabase) {
_genkDatabase = genkDatabase;
[self useDocument];
}
NSLog(@"Comes in the setdatabase methode.");
}
これをすべて行うと、次のログが得られます。
2012-10-22 10:42:47.444 RacingGenk[4786:c07] view appeared
2012-10-22 10:42:47.445 RacingGenk[4786:c07] comes to here
2012-10-22 10:42:47.459 RacingGenk[4786:c07] Comses in the use document
2012-10-22 10:42:47.460 RacingGenk[4786:c07] Comes in the setdatabase methode.
2012-10-22 10:42:47.461 RacingGenk[4786:c07] database created on disk
ご覧のとおり、使用ドキュメントの作成ログは印刷されません。したがって、メソッドFetchDataIntoDocumentを実行することはできません。
誰かがこの問題で私を助けることができますか?私は今のところこの問題を何年もの間探しています。
前進してくれてありがとう。
ステフ