Temel verilerle başa çıkmak için UIManagedDocument temelinde bir uygulamada kalıcı bir mağaza yüklemeye çalışıyorum.iOS UIManagedDocument: önceden yüklenmiş kalıcı mağazayı açamıyor
ben app B'de kullanmayı deneyin Kalıcı mağaza, "oluşturulan" ve Justin Driscoll adlı UIManagedDocument işleyicisi kullanmak üzere uygulama A ve B ikisinde de uygulama A. sayesinde doldurulur (available here, teşekkürler Bay Driscoll!). Tüm uygulamada mükemmel çalışır A.
Bu başlıkta açıklanan tekniklere dayanarak: Pre-load core data database in iOS 5 with UIManagedDocument, Kalıcı mağazayı B paketinin uygulama paketine koymaya ve gerekiyorsa bu mağazayı belgeler klasörüne kopyalamaya çalışıyorum. önce yapılır) hemen başlatmadan önce init.
Paketten belgeye kopyalama tamam (farklı yöntem denedim ve bulucu ve nslog sayesinde oluşturmayı kontrol ettim), ancak "belgeyi" açamıyorum. Uygulama kilitlenmiyor, görünümler gösteriliyor ancak tablolar boş (Aynı fetchedResultsController ile aynı uygulama kodunu A olarak kullanıyorum). Öncelikle kalıcı mağaza kopyalandığını düşündüm, sonra belgeyi/kopyalanan kalıcı mağazayı doğru açamadığımı fark ettim) => Belge durumu = 5, UIDocumentStateClosed ve UIDocumentStateSavingError hatası (eğer doğru bir şekilde yorumladım)? ?)
(Not: Ben de örneğini ve paket doğrudan belgeyi açmak için denedim ve aynı sorun var: = 5)
Yani ... Üç gün ile mücadele doc devlet Bu belge durum = 5 ve neyin düzeltileceği hakkında hiçbir ipucu
Uygulama B paketine koyduğum dosyada bir sorun olduğunu hayal ediyorum (şu anda sürükleyip bırakıyorum xcode bulucu ile "herhangi bir eklenmiş klasör için klasör referansları oluştur" seçili) Belki de bazı seçenekler, meta veriler veya dosya izinleri hakkında veya ...
Neyin araştırılacağı hakkında bir fikriniz var mı?
(Aşağıdaki kodla ilgili olduğunu sanmıyorum ama iyi ...) İşte ben init (Justin Driscoll işleyicisine dayanarak. Yalnızca custo şudur: Belgeler klasöründe bir mağaza paketi olup olmadığını kontrol ediyorum, eğer değil ben
- (id)init
{
self = [super init];
if (self) {
self.document = nil;
NSLog(@"--- INIT ---");
// On vérifie si il y a un dossier "My-Default-Document-As-Database" (notre persitent store) dans le dossier "Documents"
NSString *docDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docFolderPath = [docDirectory stringByAppendingPathComponent:@"My-Default-Document-As-Database"];
if (![[NSFileManager defaultManager] fileExistsAtPath:docFolderPath]) {
NSError *error = nil;
NSLog(@"Pas de fichier trouvé à l'adresse docFolderPath, on va donc y créer notre persistent store");
// COPY FROM BUNDLE
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *DB = [docFolderPath stringByAppendingPathComponent:@"StoreContent"];
[fileManager createDirectoryAtPath:DB withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"create directory error: %@",error);
DB = [DB stringByAppendingPathComponent:@"persistentStore"];
NSString *shippedDB = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"persistentStore"];
NSLog(@"%d",[fileManager fileExistsAtPath:shippedDB]);
[fileManager copyItemAtPath:shippedDB toPath:DB error:&error];
NSLog(@"Copy error %@",error);
}
NSLog(@"== My-Default-Document-As-Database OK DANS DOCUMENTS ==");
NSURL *myDbUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
myDbUrl = [myDbUrl URLByAppendingPathComponent:@"My-Default-Document-As-Database/"];
self.document = [[UIManagedDocument alloc] initWithFileURL:myDbUrl];
NSLog(@"== initWithFileUrl ==");
// Set our document up for automatic migrations
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
self.document.persistentStoreOptions = options;
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(objectsDidChange:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.document.managedObjectContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contextDidSave:)
name:NSManagedObjectContextDidSaveNotification
object:self.document.managedObjectContext];
}
return self;
}
Sadece "modifikasyonlar" Bay Driscoll tarafından sağlanan performWithDocument koduna yapılan pakette dosyası) dayalı oluşturmak (doc durumunu hapening neler olduğunu görmek için bazı NSLog olan her on 1'den 5'e kadar gitmek önce açın ve sonra 5'e yapıştırabilirsiniz ...)
- (void)performWithDocument:(OnDocumentReady)onDocumentReady
{
NSLog(@"passage par performWithDoc");
void (^OnDocumentDidLoad)(BOOL) = ^(BOOL success) {
NSLog(@"FilePath Apres = %@",[self.document.fileURL path]);
NSLog(@"STATE === %d", self.document.documentState);
onDocumentReady(self.document);
};
NSLog(@"FilePath Avant = %@",[self.document.fileURL path]);
NSLog(@"STATE === %d", self.document.documentState);
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.document.fileURL path]]) {
[self.document saveToURL:self.document.fileURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:OnDocumentDidLoad];
NSLog(@"performWithDoc > fileexistAtPath nope => saveToURLForCreating");
NSLog(@"STATE === %d", self.document.documentState);
} else if (self.document.documentState == UIDocumentStateClosed) {
[self.document openWithCompletionHandler:OnDocumentDidLoad];
NSLog(@"performWithDoc > UIDocStateClosed => openWithCompletionHandler");
NSLog(@"STATE === %d", self.document.documentState);
} else if (self.document.documentState == UIDocumentStateNormal) {
OnDocumentDidLoad(YES);
NSLog(@"performWithDoc > docState = normal => docdidLoad(YES)");
}
NSLog(@"STATE === %d", self.document.documentState);
}
iOS için bu seçenekler mevcut değildir: Bir önceki kod İlişkin
, böyle bir şey olması gerekir. Sorulardaki kod bu seçenekler olmadan çalıştı. – vaichidrewar
@vaichidrewar garip, aslında benim için değil. Taşınan persistentStore'u kullanabilmek için bu seçeneği NSIgnorePersistentStoreVersioningOption eklemek zorundayım (seçeneği olmadan, uygulama her zaman mağazayı açmayı reddeder).Seçenekler iOS belgesinde ayrıntılı olarak açıklanmıştır: http://developer.apple.com/library/ios/#Documentation/Cocoa/Reference/CoreDataFramework/Classes/NSPersistentStoreCoordinator_Class/NSPersistentStoreCoordinator.html – macbeb
Sanırım bunlar için gerekli değildir. iphone ios. Xcode, iPhone uygulamasını geliştirirken bu seçenekleri tanımıyordu. Ancak bunlar Mac uygulaması için geçerli olmalıdır – vaichidrewar