开发者

Can not find plist file in documents directory? How to modify the plist programmatically?

开发者 https://www.devze.com 2023-04-12 23:27 出处:网络
I have an application in Xcode 4.2. I have created plist file as my requirement. I have found the data from Applications main bundle and got the data in to the array.

I have an application in Xcode 4.2.

I have created plist file as my requirement.

I have found the data from Applications main bundle and got the data in to the array.

But As I want to modify the plist data at run time, I could not find it in Documents Directory

Actually I want to modify the plist programmatically. Though I am not using mainbundle.

-(NSString *) saveFilePath::(NSString *)tagString     
{
    NSArray *arr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *strPath = [[arr objectAtIndex:0] stringByAppendingPathComponent:tagString开发者_JAVA百科];       
    return strPath;
} 

Could not retrive the plist file.(Path I am getting, but path with file not getting)

I also could not find physically the plist file in the iphone simulator/App/Documents folder?


you need to copy plist from bundle to document directory first

-(void) checkAndCreateSetting
{
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath= [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Settings.plist"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

let me know in case of any query thanks& regards neil

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号