LittleFunny
LittleFunny

Reputation: 8375

Are there any permission when creating file in the resource Path in mainBundle

I want to be able to create, rename or remove the temporary file inside the resourcePath from the mainBundle.

NSString* path = [[NSBundle mainBundle] resourcePath];
NSFileManager* filemgr = [NSFileManager defaultManager];

for (int i=0; i<size; i++)
{
    NSString* file = [NSString stringWithFormat:@"%@/_%i.jpg", path, i];

    if ([filemgr fileExistsAtPath:file] == YES)
    {
        [filemgr removeItemAtPath:file error: NULL];
    }

    [file release];
}

[filemgr release];

Do I need extra permission to run this on a real device?

Upvotes: 0

Views: 328

Answers (2)

cactis
cactis

Reputation: 305

You can detect simulator or device, in simulator generated files in your project's resources folder, and get the from resources path in device.

Upvotes: 0

lawicko
lawicko

Reputation: 7344

It is not possible to create/rename/remove anything inside the main bundle resource directory on the device. On the simulator it seems to work though. The common solution for this is to copy the resources from the bundle to the documents directory of your app, and operate on the copies.

This is how you get the documents directory:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

Similar question was asked before.

Upvotes: 2

Related Questions