Thursday, 16 February 2012

iPhone Code: how to cancel NSURLConnection

iPhone Code: how to cancel NSURLConnection: If the Connection still in progress means just considered as "connection" is a object of NSURLConnection then, ...

iPhone Code: write file to document directory

iPhone Code: write file to document directory: NSData *data=[[NSData alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"tamil.txt" ofType:nil] encoding:NSUTF8StringEnco...

Friday, 13 January 2012

write file to document directory


NSData *data=[[NSData alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"tamil.txt" ofType:nil] encoding:NSUTF8StringEncoding error:nil]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *writePath=[documentDirectory stringByAppendingPathComponent:@"tamil.txt"];
[data writeToFile: writePath atomically:YES];

Thursday, 12 January 2012

how to cancel NSURLConnection

If the Connection still in progress means
                just considered as "connection" is a object of  NSURLConnection
then,
         if(connection)
{
[connection cancel];
}

Tuesday, 10 January 2012

get file from resources folder

If you considered tamil.txt file exist in resources folder you want to get the content of file.
step 1:
         First get the file path from resources folder

 NSString *path=[[NSBundle mainBundle] pathForResource:@"tamil.txt" ofType:nil];

Step 2:
      Then get content from path
  NSString *Content=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(@"content===%@",Content);  

Monday, 9 January 2012

load url with fragment

hi,
   If your url has fragment means you have to extract that fragment alone.Then load basic url with fragment it will work.

NSString* webStringURL = /*enter your file path here*/;
NSURL* url = [NSURL URLWithString:webStringURL];
NSString *fragment=[url frament];
NSURL *baseURL = [NSURL fileURLWithPath:tmp];
NSURL *fullURL = [NSURL URLWithString:[NSString stringWithFormat:@"#%@",fragment] relativeToURL:baseURL]; 
[webView loadRequest:[NSURLRequest requestWithURL:url]];

Sunday, 8 January 2012

get path from known url


NSArray *pathstr1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [pathstr1 objectAtIndex:0];
NSString *pathString=[documentDirectory stringByAppendindString:@"/tamil.txt"];

NSUrl *url=[NSURL fileURLWithPath:pathString];
NSString *path=[url path];
NSLog(@"path==%@",path);