Skip to content

Instantly share code, notes, and snippets.

@jeksys
Created October 7, 2011 18:40
Show Gist options
  • Save jeksys/1271047 to your computer and use it in GitHub Desktop.
Save jeksys/1271047 to your computer and use it in GitHub Desktop.
Download URL
@interface LoaderURL : NSObject
{
NSMutableData *responseData;
NSURLConnection *connectionXML;
}
@property (nonatomic, copy) NSString *xmlFileName;
- (BOOL) updateFile;
@end
@implementation w2gLoader
@synthesize LoaderURL;
- (id)init
{
self = [super init];
if (self) {
}
self.xmlFileName = @"http://www.com/file.html";
return self;
}
- (BOOL) updateFile
{
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.xmlFileName]];
connectionXML = [[NSURLConnection alloc] initWithRequest:request delegate:self];
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
NSLog(@"didReceiveData: %d kB", [responseData length]/1024);
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSLog(@"%d", [responseString length]);
[responseString release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment