-
-
Save zinwalin/b13db49a5720be6b71d1c1f732fdb056 to your computer and use it in GitHub Desktop.
Copy file from bundle to documents directory in iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment