Apple拒绝了我的应用程序,其中包含崩溃日志,表明他们已在使用iOS 8.0.2的iPhone 6上测试过它。我使用相同的iPhone 6和8.0.2测试了我的应用程序,它完美无缺。我通过iTunesConnect尝试使用testflight,假设这与Apple的测试完全相同 - 显然不是!
有没有人有一个想法,我如何解决这个问题(已经与审核小组联系,但他们无法提供帮助,因为他们说他们不是技术支持,只是测试应用程序。
我遇到的问题是(从我的观点来看,无论如何奇怪):它在添加持久存储时崩溃:
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
/*
Replace this implementation with code to handle the error appropriately. abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
它显然崩溃,因为我仍然有abort()
语句,但我不知道该怎么做(即处理问题 - 只是删除并尝试再次添加商店?)
因为它在我的iPhone上工作得很完美,我认为它不是源代码中列出的问题之一(如目录,模型等)我是对的吗? 我现在已经挣扎了几天,任何帮助或想法都不仅仅是值得赞赏!!
答案 0 :(得分:2)
发生这种情况的常见原因是storeURL上已存在文件且不符合您指定的模型。
作为解决方法,您可以做到这一点 1)启用轻量级迁移 2)删除现有文件,然后重试
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES,
NSInferMappingModelAutomaticallyOption: @YES
};
BOOL successOfAdding = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&error] != nil;
if (successOfAdding == NO)
{
// Check if the database is there.
// If it is there, it most likely means that model has changed significantly.
if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path])
{
// Delete the database
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
// Trying to add a database to the coordinator again
successOfAdding = [_persistentStoreCoordinator addPersistentStoreWithType: NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error] != nil;
if (successOfAdding == NO)
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
关于拒绝 - 您是否有以前版本的应用? 此外,您在哪里尝试存储数据库?可能是没有访问该路径?