当用户第一次启动应用程序时,他会弹出一个窗口并且必须保存图像。它适用于模拟器和4S。但是当我用我的 3G 启动它时,只要我选择了一张图片,它就会给我一个 SIGABRT 错误。我认为这是因为图片的大小太挑了,因此占用了所有的内存——但这很奇怪,因为我把它做得更小了。这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"bild"] == nil) {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
double compressionRatio=1;
NSData *imageData=UIImageJPEGRepresentation([info objectForKey:@"bild"],compressionRatio);
while ([imageData length]>5000) {
compressionRatio=compressionRatio*0.20;
imageData=UIImageJPEGRepresentation([info objectForKey:@"bild"],compressionRatio);
}
UIImage *yourUIImage;
yourUIImage = [info objectForKey:UIImagePickerControllerOriginalImage];
imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"bild"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self dismissModalViewControllerAnimated:YES];
}
我在这一行得到 SIGABRT 错误 imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
我应该使用其他方法来调整图像大小吗?还是应该将其保存为本地文件并在每次应用程序启动时检索它?(如果它是可能的)