Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Created March 26, 2012 10:55
Show Gist options
  • Save albertodebortoli/2204433 to your computer and use it in GitHub Desktop.
Save albertodebortoli/2204433 to your computer and use it in GitHub Desktop.
Copy file from bundle to documents directory in iOS
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.filename = @"file.ext";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
self.filePath = [documentDir stringByAppendingPathComponent:self.filename];
[self createAndCheckDatabase];
// Override point for customization after application launch.
return YES;
}
- (void)createAndCheckDatabase
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:filePath];
if (success) return;
NSString *filePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.filename];
[fileManager copyItemAtPath:filePathFromApp toPath:filePath error:nil];
}
@palanisamygithubid
Copy link

Really good example.every one can easily understand...

@faridlab
Copy link

Thanks a lot,
you saved my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment