Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write new file to bundle resource directory in iOS app?

Is it possible to write new file to bundle resource directory in iOS app?

like image 749
eonil Avatar asked May 02 '11 08:05

eonil


People also ask

What is IOS app bundle?

App bundles make it easy for customers to buy up to 10 of your apps or games in a single purchase. You can create app bundles for paid apps or free apps that offer an auto-renewable subscription to access all apps in the bundle. Learn how to set up app bundles and effectively market them on your product page.


2 Answers

No there is no way to write in the bundle dir.. because the bundle dir is code signed with SSL certificate and you can't break it. however you can easily write in the documents directory of you iphone application

You can get the documents directory path using this -

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
return [paths objectAtIndex:0];
like image 180
Saurabh Avatar answered Nov 08 '22 18:11

Saurabh


Or you can copy the resources needed and then operate on files with writing permission.

NSArray  *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDir = dirPaths[0];

NSString *databasePath = [documentsDir stringByAppendingString:@"/TwigitDatabase.db"];

NSFileManager *fm = [NSFileManager defaultManager];

if(![fm fileExistsAtPath:databasePath]) {   // Checking whether the my database was copied earlier, though it could be saved in some preferences property.
    NSError *error;
        NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"TwigitDatabase" ofType:@"db"];
    [[NSFileManager defaultManager] copyItemAtPath:soundFilePath toPath:databasePath error:&error];

    NSLog(@"%@", error);


}
like image 40
Paul Brewczynski Avatar answered Nov 08 '22 16:11

Paul Brewczynski