【问题标题】:saving in NSDocumentDirectory causing crash保存在 NSDocumentDirectory 中导致崩溃
【发布时间】:2012-07-07 17:30:42
【问题描述】:

在我的应用程序中,我选择了camera roll(单张/多张图片)。然后我将这些图像保存在NSDocumentDirectory,这是我的代码:

for (int i = 0; i < info.count; i++) {
    NSLog(@"%@", [info objectAtIndex:i]);
    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,    NSUserDomainMask ,YES );
    NSString *documentsDir = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]];

            ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
            UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];

            NSData *imageData = UIImagePNGRepresentation(image);
            [imageData writeToFile:savedImagePath atomically:YES];

            NSLog(@"saving at:%@",savedImagePath);           
 }

从此,它工作正常。但是,当我在相机胶卷中再次返回然后再次保存(不重新启动应用程序)时,它有时会在实际设备中测试时崩溃(大部分时间)或滞后应用程序。我不知道它是我用来导入照片的AGImagePicker 库还是我的保存方式。我在NSDocumentDirectory 中的保存方式错了吗?或者如果有更好的方法帮助将不胜感激。

谢谢...

【问题讨论】:

  • 你试过通过启用僵尸选项来运行吗?
  • 这是我没试过的。
  • 为什么不设置异常断点?
  • 在模拟器中运行时,没问题。但是在实际设备中,这是它崩溃的主要时间。
  • 在此处粘贴您的设备错误日志..

标签: iphone ios ipad nsdocumentdirectory


【解决方案1】:

尝试启用 Zombie 对象并运行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多