-->

Strange app crash on iPhone - not rejected by Appl

2019-07-19 07:51发布

问题:

I recently submitted my app to Apple through iTunes Connect, and it is now in the iTunes store. However, when I downloaded it onto a friend's iPhone, it crashes immediately. I tested it on the iPhone simulator and my iPad (I don't have an iPhone). So, I plugged the iPhone into my computer and got this crash log from it:

            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

Next, I deleted the original app and put it on the iPhone through xcode 4. I tried running it this way, and it crashed with this error:

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";
}

I tried replacing the string for pathForResource in the following method with the exact name of my most recent store (Appv4), but it tells me that the path for the database is null.

- (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_;
}

After trying to run the application several times on the iPhone through xcode, it suddenly started working. However, the same does not occur for the version on the app store.

Please help! I can't figure out what is wrong.

EDIT: Here is my AppDelegate.m file

#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

回答1:

You might try this: Can’t find model for source store. According to the author, "Can't find model for source store" "means that either your object model and generated/coded model codes are out of sync or your db is not migrated/upgraded correctly to the new version." He recommends using this code:

 NSDictionary *optionsForSTore = [NSDictionary dictionaryWithObjectsAndKeys: 

 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,

 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];