die Sie interessieren in AppDelegate Klasse
.h-Datei
@property(nonatomic, retain) NSString *dbPath;
.m-Datei
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self copyDatabaseIfNeeded];
}
- (void) copyDatabaseIfNeeded
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(!success)
{
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sampleDB.sqlite3"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
/********* Database Path *********/
- (NSString *) getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"sampleDB.sqlite3"];
}
It'l lch kopiere automatisch, wenn keine Datenbank in der Anwendung gefunden wird.
Hoffentlich hilft es Ihnen.
Danke.
Bitte stellen Sie sicher, für solche Fragen, die Sie tun Liste Verweise auf What Have You Quellen Versuchte oder einfach in Ihrem Code hier zu schreiben, so dass jeder yur Methode/Ansatz – madLokesh