【问题标题】:Intermittent error accessing core data model / contacts database访问核心数据模型/联系人数据库时出现间歇性错误
【发布时间】:2012-04-13 00:16:46
【问题描述】:

我的 iOS 应用程序出现错误。令人沮丧的是,这是一个间歇性错误——我正在执行的任务连续运行 5 或 6 次,然后意外崩溃。错误日志表明打开 sqlite 数据库时出错 - 大概是我的应用程序中的核心数据模型。但是 Xcode 显示发生错误的行是访问 Apple 联系人数据库。所以我不清楚发生了什么。错误日志如下。任何人都可以解释下面的输出并对此有所了解吗?

    warning: Could not compile statement PRAGMA journal_mode = wal;: unable to open database file
error 14 creating properties table: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson;: unable to open database file
warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson;: unable to open database file
warning: Could not compile statement INSERT OR REPLACE INTO _SqliteDatabaseProperties VALUES (?, ?);: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement INSERT OR REPLACE INTO _SqliteDatabaseProperties VALUES (?, ?);: unable to open database file
2012-03-29 11:43:13.813 iPT[10500:11303] Error loading /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): no suitable image found.  Did find:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator: open() failed with errno=24
2012-03-29 11:43:13.814 iPT[10500:11303] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson WHERE ROWID = ?;: unable to open database file

崩溃发生时我正在执行的代码是……

Client *client = [mutableFetchResults objectAtIndex:loop];
            ABRecordID recordID = [client.addressBookID intValue];
            ABRecordRef person = ABAddressBookGetPersonWithRecordID (addressBook,recordID);
            NSString *clientFirstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
            NSString *clientLastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
            NSString *clientCompositeName = [NSString stringWithFormat:@"%@ %@", clientFirstName, clientLastName];

【问题讨论】:

    标签: iphone objective-c ios core-data abaddressbook


    【解决方案1】:

    我假设您正在以下列方式声明地址簿?

        ABAddressBookRef addressBook = ABAddressBookCreate();
    

    【讨论】:

    • 是的 - 就在我声明 *client 的上方。
    • 如果您对客户端对象进行 NSLog 记录,此时是否会发生错误?如果是这样,那么问题很可能是您在持久存储中设置的迁移选项。 NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
    • 抱歉,我不完全理解答案。你会建议我在哪里创建一个 NSLog?另外,我应该在某处寻找该代码来更改设置,还是需要将其插入某处?如果这些是愚蠢的问题,我们深表歉意!
    • 没问题 Ben... 在你的代码中,在客户端赋值之后,添加这个语句: NSLog(@"%@ %d", client, [client.addressBookID intValue] );
    • 它顺利通过了那个阶段。它在 NSString *clientFirstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 处失败行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    相关资源
    最近更新 更多