Reading/Writing Plist Data
-(NSString *)PlistData
{
BOOL success;
NSString *BasicURL;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *writableDBPath = [self GetDBPath];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success)
{
plistData = [NSMutableDictionary dictionaryWithContentsOfFile:writableDBPath];
BasicURL=[plistData objectForKey:@"URL"];
}
else
{
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"BasicUrl.plist"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
else
{
plistData = [NSMutableDictionary dictionaryWithContentsOfFile:writableDBPath];
BasicURL=[plistData objectForKey:@"URL"];
}
}
return BasicURL;
}
- (NSString *)GetDBPath
{
NSString *Path=nil;
if(Path==nil) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
Path = [documentsDirectory stringByAppendingPathComponent:@"BasicUrl.plist"];
}
return Path;
}
{
BOOL success;
NSString *BasicURL;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *writableDBPath = [self GetDBPath];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success)
{
plistData = [NSMutableDictionary dictionaryWithContentsOfFile:writableDBPath];
BasicURL=[plistData objectForKey:@"URL"];
}
else
{
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"BasicUrl.plist"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
else
{
plistData = [NSMutableDictionary dictionaryWithContentsOfFile:writableDBPath];
BasicURL=[plistData objectForKey:@"URL"];
}
}
return BasicURL;
}
- (NSString *)GetDBPath
{
NSString *Path=nil;
if(Path==nil) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
Path = [documentsDirectory stringByAppendingPathComponent:@"BasicUrl.plist"];
}
return Path;
}
Comments
Post a Comment