I am trying to create a Simple single File Downloader in cocoa.. I am using VMWARE with MAC OS 10.5 image
Here is the code of main.m, but it is not working. Not showing any error or warning message nor downloading any file.
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
NSString *urlString = @"http://www.mig33.com/wap2/v4_50/24x24/mig33v45.jar";
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *dataPath = @"~/Desktop/mig33v45.jar";
[data writeToFile:dataPath atomically:YES];
return NSApplicati开发者_Go百科onMain(argc, (const char **) argv);
}
Where i am doing wrong? I am new in cocoa programing.
-Thanks -regards
You also need an NSAutoreleasePool and you don't need the NSApplicationMain call.
this works:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *urlString = @"http://www.mig33.com/wap2/v4_50/24x24/mig33v45.jar";
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *dataPath = [@"~/Desktop/mig33v45.jar" stringByExpandingTildeInPath];
[data writeToFile:dataPath atomically:YES];
[pool drain];
return 0;
}
Have you tried:
NSString *dataPath = [@"/Desktop/mig33v45.jar" stringByExpandingTildeInPath];
精彩评论