我試圖讓我的iOS6.0應用與5.1兼容。我已經關掉了一些明顯的事情(例如自動佈局),但我陷入了一個奇怪的舞臺。iOS 5.1 openWithCompletionHandler不會跑步
我的應用程序從XML源獲取數據並將其放入核心日期結構中。在iOS 6上,這完美地工作。在iOS 5它被困在這裏
else if (self.dataStorage.documentState == UIDocumentStateClosed) {
NSLog(@"THIS FIRES = db on disk but closed");
[self.dataStorage openWithCompletionHandler:^(BOOL success) {
NSLog(@"THIS NEVER FIRES");
}];
}
如果我看self.datastorage這是我所期待的(一個封閉的管理文檔)】fileurl:文件://本地主機/ ...... /庫/應用程序%20Support/iPhone%20Simulator/5.1/Applications/E3E9192D-2DFE-4882-9041-00A1DF9E98D6/Documents/Default%20Database documentState:[Closed]
編輯:實際上,iOS 5.0或6.0+可以正常工作。我的問題純粹是在iOS模擬器上運行iOS 5.1。難道這只是模擬器的錯誤?它不會打開一個關閉的UIManagedDocument,也不會創建一個不存在的文件。
下面是完整的全碼:
- (void)setDataStorage:(UIManagedDocument *)database
{
if (_dataStorage != database) {
_dataStorage = database;
[self useDocument];
}
}
-(UIManagedDocument*) initialiseDatabase {
if (!self.dataStorage) {
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"DefaultDatabase"];
self.dataStorage = [[UIManagedDocument alloc] initWithFileURL:url]; // setter will create this for us on disk
}
return self.dataStorage;
}
- (void)useDocument {
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.dataStorage.fileURL path]]) {
// does not exist on disk, so create it
NSLog(@"db not on disk");
[self.dataStorage saveToURL:self.dataStorage.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
NSLog(@"Doesn't fire");
}];
} else if (self.dataStorage.documentState == UIDocumentStateClosed) {
NSLog(@"db on disk but closed");
// exists on disk, but we need to open it
[self.dataStorage openWithCompletionHandler:^(BOOL success) {
NSLog(@"Doesn't fire");
}];
} else if (self.dataStorage.documentState == UIDocumentStateNormal) {
NSLog(@"db on disk and open");
}
}
感謝