This is the code for downloading file and saving it on the device or Simulator (i.e. On Machine).
This is the code for downloading file and saving it on the device or Simulator (i.e. On Machine)... It is not the Exact code but I hope it should help you.... @interface URLConnect : NSObject { NSMutableString *textView; NSMutableData *receivedData; NSURLRequest* DownloadRequest; NSURLConnection* DownloadConnection; long long bytesReceived; long long expectedBytes; } @property (nonatomic,retain) NSMutableData *receivedData; @property (nonatomic, readonly, retain) NSURLRequest* DownloadRequest; @property (nonatomic, readonly, retain) NSURLConnection* DownloadConnection; . M file #import "URLConnect.
H" @implementation URLConnect // synthesize the properties - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { receivedData appendData:data; unsigned char byteBufferreceivedData length; receivedData getBytes:byteBuffer; NSLog(@"Data === %ld",receivedData); NSInteger receivedLen = data length; bytesReceived = (bytesReceived + receivedLen); NSLog(@"received Bytes == %f",bytesReceived); if(expectedBytes! = NSURLResponseUnknownLength) { NSLog(@"Expected Bytes in if == %f",expectedBytes); NSLog(@"received Bytes in if == %f",bytesReceived); float value = ((float) (bytesReceived *100/expectedBytes))/100; NSLog(@"Value == %f",value); } } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { connection release; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { expectedBytes = response expectedContentLength; NSLog(@"%f",expectedBytes); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { // code for downloading file to device or simulator NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = paths objectAtIndex:0; NSString *pdfPath = documentsDirectory stringByAppendingPathComponent:@"AnyName. Txt"; unsigned char byteBufferreceivedData length; receivedData getBytes:byteBuffer; self.
ReceivedData writeToFile:pdfPath atomically:YES; DownloadConnection release; } - (void)viewDidLoad { super viewDidLoad; NSURL *targetURL = NSURL URLWithString:urlString; DownloadRequest = NSURLRequest requestWithURL:targetURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:50.0; DownloadConnection = NSURLConnection alloc initWithRequest:DownloadRequest delegate:self; if (DownloadConnection) { receivedData = NSMutableData dataretain; } // display your textfile here }.
MAc this isnt working for me...same issue, 0 bytes in receivedData, and I don't have a "viewDidLoad" in outside. And no logs were displayed – chetan Nov 24 at 6:48 Why you havent have viewDidLoad method? – mAc Nov 24 at 7:31 I dint get what super viewDidLoad; does – chetan Nov 24 at 7:42 It is used to call the parent View to load first.
Have you extended your viewController with UIViewController then only you will get viewDidLoad method in his Properties.... and then overirde viewDidLoad method by calling super first and then try the code..:) – mAc Nov 24 at 7:55.
It sounds like you didn't actually set the delegate property on your instance of NSURLConnection. That would explain why the NSLogs in the delegate methods aren't printing out.
I have added the code. Please any help – chetan Nov 24 at 5:49 Are you getting any warnings or errors? – Mark Adams Nov 24 at 5:50 no warnings/errors but the size of responseData is 0 bytes – chetan Nov 24 at 5:58.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.