Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem writing string to a file ...(iPhone SDK )
    primarykey
    data
    text
    <p>I want to grab all URL's accessed in webview and write them to a text file.I don't want to use writeToFile coz in -(BOOL)webView method it would overwrite instead of appending to file. I can create file but all it writes to that file is string I used to create the file using FileManager createFileAtPath with Content ... Also in the -(BOOL) webView method... when I tried to see if the file is read-only or writable ( isWritableFileAtPath ) it gives read-only. POSIX Permissions in viewDidLoad -> 511 ... checked file attributes in terminal going to that location its -rwxrwxrwx I am new to Stack Overflow don't know how to post code here so using pastebin...<a href="http://pastebin.com/Tx7CsXVB" rel="nofollow">http://pastebin.com/Tx7CsXVB</a></p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [myBrowser loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]]; // UIWebView *myBrowser; is an instance variable NSFileManager *fileMgr=[NSFileManager defaultManager]; NSDictionary* fileAttrs = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:777] forKey:NSFilePosixPermissions]; /*for setting attribute to rwx for all users */ NSDictionary *attribs; // To read attributes after writing something to file NSString *aPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/file1.txt"]; myBrowser.delegate = self; // UIWebView delegate Self // if the File Doesn't exist create one if([fileMgr fileExistsAtPath:aPath]) { NSLog(@"File Exists at this Location"); } else { NSString *someString = @"This is start of file"; NSData *startString =[someString dataUsingEncoding: NSASCIIStringEncoding]; [fileMgr createFileAtPath:aPath contents:startString attributes: fileAttrs]; // earlier attributes was nil changed to fileAttrs } NSLog(@"aPath is %@",aPath); attribs = [fileMgr attributesOfItemAtPath:aPath error: NULL]; NSLog (@"Created on %@", [attribs objectForKey: NSFileCreationDate]); NSLog (@"File type %@", [attribs objectForKey: NSFileType]); NSLog (@"POSIX Permissions %@", [attribs objectForKey: NSFilePosixPermissions]); } //UIWebView delegate calls this method every time user touches any embedded URL's in the current WebPage. I want to grab all the URL's accessed and write them to file. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSFileManager *fileManager =[NSFileManager defaultmanager]; NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/file1.txt"]; fileHandle = [NSFileHandle fileHandleForWritingAtPath:path]; [fileHandle seekToEndOfFile]; // Moved up next to fileHandleForWritingAtPath since the above would place pointer to start of file again so setting handle to seek to End of File /* section of code to check if the file at that path is writable or not */ if ([fileManager isWritableFileAtPath:path] == YES) NSLog (@"File is writable"); else NSLog (@"File is read only"); /* section of code to check if the file at that path is writable or not ENDS*/ NSURL *url = request.URL; NSString *currenturl = url.absoluteString; NSString *currentURL = [NSString stringWithFormat:@"%@\n",currenturl]; NSString *str =[NSString stringWithFormat:@"%@",currentURL];/* has already been set up */ [fileHandle writeData:[str dataUsingEncoding:NSUTF8StringEncoding]]; // testing if string has been written to file by reading it... NSData *dataBuffer = [fileMgr contentsAtPath:path]; NSString *some; some = [[NSString alloc] initWithData:dataBuffer encoding:NSASCIIStringEncoding]; NSLog(@"SOme String is: %@",some); [fileHandle closeFile]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload