Hi guys,
I am using the latest iphone SDK (Beta 3). I am getting an image from an URL, and then trying to save it via the NSData's writeToFile function to a file in the app's Documents folder. It crashes with EXC_BAD_ACCESS.
Do you have any idea why ? Thanks very much.
The code is the following:
==================== myappAppDelegate.m ==========
- (void)applicationDidFinishLaunchingUIApplication *)application {
[window makeKeyAndVisible];
NSFileManager *defaultManager;
defaultManager = [NSFileManager defaultManager];
NSString *filename = @"savedImage.jpg";
NSString *url = @"http://www.promovid.co.nz/images/ms_logo.jpg";
NSData *imageData;
NSURL *imageURL = [[NSURL alloc] initWithString:url];
if (imageURL) {
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:filename];
NSLog(appFile);
[imageData writeToFile:appFile atomically:YES];
}
=============================================
I am using the latest iphone SDK (Beta 3). I am getting an image from an URL, and then trying to save it via the NSData's writeToFile function to a file in the app's Documents folder. It crashes with EXC_BAD_ACCESS.
Do you have any idea why ? Thanks very much.
The code is the following:
==================== myappAppDelegate.m ==========
- (void)applicationDidFinishLaunchingUIApplication *)application {
[window makeKeyAndVisible];
NSFileManager *defaultManager;
defaultManager = [NSFileManager defaultManager];
NSString *filename = @"savedImage.jpg";
NSString *url = @"http://www.promovid.co.nz/images/ms_logo.jpg";
NSData *imageData;
NSURL *imageURL = [[NSURL alloc] initWithString:url];
if (imageURL) {
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:filename];
NSLog(appFile);
[imageData writeToFile:appFile atomically:YES];
}
=============================================