我最近通过iTunes Connect将我的应用程序提交给Apple,现在它已经在iTunes商店中。但是,当我将它下载到朋友的iPhone上时,它会立即崩溃。我在iPhone模拟器和我的iPad上测试过它(我没有iPhone)。所以,我将iPhone插入我的电脑并从中获取了这个崩溃日志:
Incident Identifier: 893F48B6-9805-4BF7-BA84-D5CDF85392E8
CrashReporter Key: 72f4227f4240642bb75dcb75873b6f4b42cf3cf7
Hardware Model: iPhone3,1
Process: App [305]
Path: /var/mobile/Applications/4A493313-CB6D-422D-8098-BB2DE94A30B2/-----.app/-----
Identifier: App
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2012-03-10 13:40:30.841 -0700
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x35d7732c 0x35d66000 + 70444
1 libsystem_c.dylib 0x32c40f54 0x32bf3000 + 319316
2 libsystem_c.dylib 0x32c39fe4 0x32bf3000 + 290788
3 GraphicsServices 0x30637444 0x30633000 + 17476
4 GraphicsServices 0x30637e84 0x30633000 + 20100
5 UIKit 0x37233520 0x37202000 + 202016
6 App 0x000104d0 main (main.m:14)
7 App 0x00010488 start + 32
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x35d673b4 0x35d66000 + 5044
1 libdispatch.dylib 0x36a91e78 0x36a85000 + 52856
2 libdispatch.dylib 0x36a91b96 0x36a85000 + 52118
Thread 2:
0 libsystem_kernel.dylib 0x35d77cd4 0x35d66000 + 72916
1 libsystem_c.dylib 0x32bfd30a 0x32bf3000 + 41738
2 libsystem_c.dylib 0x32bfd09c 0x32bf3000 + 41116
Thread 3:
0 libsystem_kernel.dylib 0x35d77cd4 0x35d66000 + 72916
1 libsystem_c.dylib 0x32bfd30a 0x32bf3000 + 41738
2 libsystem_c.dylib 0x32bfd09c 0x32bf3000 + 41116
Thread 4 name: WebThread
Thread 4:
0 libsystem_kernel.dylib 0x35d67010 0x35d66000 + 4112
1 libsystem_kernel.dylib 0x35d67206 0x35d66000 + 4614
2 CoreFoundation 0x33e3041c 0x33da3000 + 578588
3 CoreFoundation 0x33e2f154 0x33da3000 + 573780
4 CoreFoundation 0x33db24d6 0x33da3000 + 62678
5 CoreFoundation 0x33db239e 0x33da3000 + 62366
6 WebCore 0x36286128 0x361de000 + 688424
7 libsystem_c.dylib 0x32c02c16 0x32bf3000 + 64534
8 libsystem_c.dylib 0x32c02ad0 0x32bf3000 + 64208
Thread 0 crashed with ARM Thread State:
r0: 0x00000000 r1: 0x00000000 r2: 0x00000001 r3: 0x00000000
r4: 0x00000006 r5: 0x3e52ace8 r6: 0x3f28dfe0 r7: 0x2fe0dc84
r8: 0x2fe0dd60 r9: 0x0012ca70 r10: 0x00000001 r11: 0x00000000
ip: 0x00000148 sp: 0x2fe0dc78 lr: 0x32c40f5b pc: 0x35d7732c
cpsr: 0x00000010
接下来,我删除了原始应用并通过xcode 4将其放在iPhone上。我尝试以这种方式运行它,并且它因此错误而崩溃:
2012-03-09 22:05:23.980 App[15930:707] Unresolved error in persistentStoreCoordinator Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x199a10 {URL=file://localhost/var/mobile/Applications/B7B2F695-B599-40A3-8D5A-88E1B7E1C148/Documents/App.sqlite, metadata=<CFBasicHash 0x17a8a0 [0x3ef4c630]>{type = immutable dict, count = 7,
entries =>
2 : <CFString 0x17eb10 [0x3ef4c630]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x17ec10 [0x3ef4c630]>{type = immutable, count = 1, values = (
0 : <CFString 0x3ef409d0 [0x3ef4c630]>{contents = ""}
)}
4 : <CFString 0x17eb40 [0x3ef4c630]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x1796d0 [0x3ef4c630]>{value = +386, type = kCFNumberSInt64Type}
6 : <CFString 0x17eb70 [0x3ef4c630]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x17ece0 [0x3ef4c630]>{type = immutable dict, count = 2,
entries =>
1 : <CFString 0x3ef3df50 [0x3ef4c630]>{contents = "Camera"} = <CFData 0x17ec40 [0x3ef4c630]>{length = 32, capacity = 32, bytes = 0x497312a7c61a2dc8fe30e74ecc001ebc ... 1b5a15fa47a27413}
2 : <CFString 0x17ec30 [0x3ef4c630]>{contents = "Team"} = <CFData 0x17ec90 [0x3ef4c630]>{length = 32, capacity = 32, bytes = 0x401bd3f39f173666c4b24d43944d2562 ... 35b2b372c7051eed}
}
7 : <CFString 0x3ea9cf40 [0x3ef4c630]>{contents = "NSStoreUUID"} = <CFString 0x17e800 [0x3ef4c630]>{contents = "44E18608-E974-4E3D-A4F0-EB7C836869B4"}
8 : <CFString 0x3ea9cde0 [0x3ef4c630]>{contents = "NSStoreType"} = <CFString 0x3ea9cdf0 [0x3ef4c630]>{contents = "SQLite"}
9 : <CFString 0x17ebc0 [0x3ef4c630]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x17ed40 [0x3ef4c630]>{contents = "2"}
10 : <CFString 0x17ebe0 [0x3ef4c630]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x157050 [0x3ef4c630]>{value = +3, type = kCFNumberSInt32Type}
}
, reason=Can't find model for source store}, {
URL = "file://localhost/var/mobile/Applications/B7B2F695-B599-40A3-8D5A-88E1B7E1C148/Documents/App.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 386;
NSStoreModelVersionHashes = {
Camera = <497312a7 c61a2dc8 fe30e74e cc001ebc 6282715c 1751f100 1b5a15fa 47a27413>;
Team = <401bd3f3 9f173666 c4b24d43 944d2562 a3a17942 4bd878d0 35b2b372 c7051eed>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "44E18608-E974-4E3D-A4F0-EB7C836869B4";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
我尝试使用我最近的商店(Appv4)的确切名称替换以下方法中的pathForResource字符串,但它告诉我数据库的路径为空。
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"App" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
尝试通过xcode在iPhone上多次运行应用程序后,它突然开始工作了。但是,应用程序商店中的版本不会出现同样的情况。
请帮忙!我无法弄清楚出了什么问题。
编辑:这是我的AppDelegate.m文件
#import "AppAppDelegate.h"
#import "RootViewController.h"
@implementation AppAppDelegate
@synthesize window;
@synthesize navigationController;
//@synthesize managedObjectModel_, managedObjectContext_;
#pragma mark -
#pragma mark Application lifecycle
- (void)awakeFromNib {
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
rootViewController.managedObjectContext = self.managedObjectContext;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[self saveContext];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
/**
applicationWillTerminate: saves changes in the application's managed object context before the application terminates.
*/
- (void)applicationWillTerminate:(UIApplication *)application {
[self saveContext];
}
- (void)saveContext {
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&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. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error in saveContext %@, %@", error, [error userInfo]);
abort();
}
}
}
#pragma mark -
#pragma mark Core Data stack
/**
Returns the managed object context for the application.
If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
*/
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext_ != nil) {
return managedObjectContext_;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}
/**
Returns the managed object model for the application.
If the model doesn't already exist, it is created from the application's model.
*/
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"App" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
/*
Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the application's store added to it.
*/
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"App.sqlite"];
NSError *error = nil;
//Auto update?
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
//
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options 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. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
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:
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
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 in persistentStoreCoordinator %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator_;
}
#pragma mark -
#pragma mark Application's Documents directory
/**
Returns the URL to the application's Documents directory.
*/
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[managedObjectContext_ release];
[managedObjectModel_ release];
[persistentStoreCoordinator_ release];
[navigationController release];
[window release];
[super dealloc];
}
@end
答案 0 :(得分:3)
您可以尝试:Can’t find model for source store。根据作者的说法,“找不到源存储的模型”“意味着您的对象模型和生成/编码的模型代码不同步,或者您的数据库未正确迁移/升级到新版本。”他建议使用此代码:
NSDictionary *optionsForSTore = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];