ios - Text file updated only device is connected with xcode only -
i created text file in ios , stored in data files in following location.sandbox => documents => mylogfile.txt.
this file updates when connected device mac , xcode only.if eject device, , connect again see updated text file. not updated. same old file. log file not updated when disconnected pc. how update text file on time.
my code:
-(void)logme:(nsstring *)mymessage { nsstring *content = mymessage; //get file path nsstring *documentsdirectory = [nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; nsstring *filename = [documentsdirectory stringbyappendingpathcomponent:@"locationlog.txt"]; //create file if doesn't exist if(![[nsfilemanager defaultmanager] fileexistsatpath:filename]) [[nsfilemanager defaultmanager] createfileatpath:filename contents:nil attributes:nil]; //append text file (you'll want add newline every write) nsfilehandle *file = [nsfilehandle filehandleforupdatingatpath:filename]; [file seektoendoffile]; [file writedata:[content datausingencoding:nsutf8stringencoding]]; [file closefile]; }
and called log file like,
[self logme:myhtml];
Comments
Post a Comment