-1

i am prepararing an ios application. i am using following code

NSString * yol=[[NSBundle mainBundle]pathForResource:@"TavsiyeKitapAile" ofType:@"plist"];


NSDictionary * tka = [XMLReader dictionaryForXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.bahcevan.org/kat.php?kat=64"]] error:nil];

[tka writeToFile:yol atomically:YES];

NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithContentsOfFile:yol];

it is working well on simulator but when i open it, i couln't see data. nothing comes. i think it is related with bundle but i couldn't solve it.

2 Answers2

2

You can't write into device bundle, Your device bundle is readonly, if you want to save/write something then you have to write it to document directory.

aahsanali
  • 3,537
  • 23
  • 21
  • 1
    on simulator app is not propertly sandboxed PLUS its in your home dir and that is writable to you. still... this seems like a 'bug' in the simulator. Please file a bug about it with apple :) – Daij-Djan Nov 24 '12 at 11:50
  • i am parsing an XML and writing it into a plist in my project. Isnt't it possible? (TavsiyeKitapAile.plist is already in my project, i created it before.) if it is how could i write it into documents directory ? – ozmuhammed Nov 24 '12 at 20:36
-1

i found the solution, it is using the directory "Documents", i used following code insted of first one :)

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

NSString *documentsDirectory = [paths objectAtIndex:0];

NSURL *yol = [NSURL fileURLWithPath:[documentsDirectory
                                     stringByAppendingString:@"/TavsiyeKitapAile.plist"]];

NSDictionary * tka = [XMLReader dictionaryForXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.bahcevan.org/kat.php?kat=64"]] error:nil];

[tka writeToURL:yol atomically:YES];


NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithContentsOfURL:yol];