Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

iphone - Core Data causing app to crash while migrating

I submitted an update of my application to the App Store which requires the Core Data model to be updated/migrated. It is only a simple change with a hand full of new attributes added, and one renamed. It seems to have gone fine for most users, however I've had 2 crash reports that I don't understand.

The crashes appear to all occur while performing automatic inferred migration. My migration options are NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption.

Does anyone have any ideas what's taking it so long to migrate? It's causing crashes every time the app launches so the app us unusable to those users. They're both running iPhone OS 3.1.2.

Any help would be greatly appreciated.

Report User A

com.foo.MyApp failed to launch in time 
elapsed total CPU time (seconds): 19.970 (user 14.130, system 5.840), 92% CPU 
elapsed application CPU time (seconds): 9.910, 45% CPU

Thread 0:
0   CoreData                        0x00093d08 -[NSPersistentStoreCoordinator dealloc] + 0
1   CoreFoundation                  0x0003963a -[NSObject release] + 28
2   CoreData                        0x000b6e0e -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1470
3   CoreData                        0x000aceb0 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 92
4   CoreData                        0x000ad6f0 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 72
5   CoreData                        0x000ac9ee -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 880
6   CoreData                        0x0000965c -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 1328

Unknown thread crashed with unknown flavor: 5, state_count: 1

Report User B

com.foo.MyApp failed to suspend in time 
elapsed total CPU time (seconds): 18.580 (user 13.320, system 5.260), 93% CPU 
elapsed application CPU time (seconds): 8.340, 42% CPU

Thread 0:
0   libsqlite3.dylib                0x00022f14 sqlite3_backup_init + 2396
1   libsqlite3.dylib                0x00025474 sqlite3_backup_init + 11964
2   libsqlite3.dylib                0x000255dc sqlite3_backup_init + 12324
3   libsqlite3.dylib                0x0002aa74 sqlite3_open16 + 16084
4   libsqlite3.dylib                0x00047838 sqlite3_prepare16 + 46920
5   libsqlite3.dylib                0x00002940 sqlite3_step + 44
6   CoreData                        0x00011958 _execute + 44
7   CoreData                        0x000113e0 -[NSSQLiteConnection execute] + 696
8   CoreData                        0x000994be -[NSSQLConnection prepareAndExecuteSQLStatement:] + 26
9   CoreData                        0x000be14c -[_NSSQLiteStoreMigrator performMigration:] + 244
10  CoreData                        0x000b6c60 -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1040
11  CoreData                        0x000aceb0 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 92
12  CoreData                        0x000ad6f0 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 72
13  CoreData                        0x000ac9ee -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 880
14  CoreData                        0x0000965c -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 1328

Unknown thread crashed with unknown flavor: 5, state_count: 1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first line is your clue as to what is going on. In both cases the Core Data persistence/saving is taking too long. The app is not crashing due to an error but it is being killed by the OS because it is not shutting down or starting up in a timely manner.

How big are the data sets for each of these users? If they are very large then you may want to consider taking control of the migration and either putting it onto a background thread or breaking it up into pieces so that the application can start up on time.

The shutdown issue indicates that you are probably not doing incremental saves while the application is running but instead doing one large save when the application shuts down. Ideally your application should save to disk whenever there is a logical break in the workflow. If you add saves into the application that will help or solve your shutdown termination issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...