objective-c - 当 PFFile 太大时应用程序崩溃

标签 objective-c xcode parse-platform

当我尝试上传大于 10mb 的 PFFile 时,我的应用程序崩溃了。我以为 Parse 会捕获错误,此时我可以显示警报 View ,但应用程序只是崩溃了。

我下面的代码可以很好地保存图像,但正如我所说,如果文件太大,它就会崩溃。

我试图用 if (error) 语句捕获错误,但没有成功。

PFQuery *query = [PFQuery queryWithClassName:@"Football_Clubs"];

    [query getObjectInBackgroundWithId:objectId block:^(PFObject *object, NSError *error)
     {
         NSData *imageData = UIImagePNGRepresentation(badgeImage);
         PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
         object[@"badge_image"] = imageFile;

         [imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
         {
             if (succeeded)
             {
                 [object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                     if (succeeded)
                     {
                         badgeImageView.image = nil;
                         [getSettingsQuery clearCachedResult];
                         [self loadSettings];
                         [progress setText:@"Saved"];
                     }
                 }];
             }
         } progressBlock:^(int percentDone)
         {
             [progress setText:[NSString stringWithFormat:@"Saving image - %d%@ complete", percentDone, @"%"]];
         }];
     }];

我的控制台日志如下:

2014-07-31 12:40:47.466 Sporter[21017:60b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“PFFile 不能大于 10485760 字节” * 首先抛出调用栈: (0x18ae1ef50 0x1973281fc 0x18ae1ee90 0x10011d550 0x1000c6ae4 0x100141334 0x197900014 0x1978fffd4 0x1979031dc 0x18addec2c 0x18addcf6c 0x18ad1dc20 0x190a05c0c 0x18de4efdc 0x1000d5218 0x19791baa0) libc++abi.dylib:以 NSException 类型的未捕获异常终止

最佳答案

PFFile 对象的大小限制为 10MB

The PFFile

PFFile lets you store application files in the cloud that would otherwise be too large or cumbersome to fit into a regular PFObject. The most common use case is storing images but you can also use it for documents, videos, music, and any other binary data (up to 10 megabytes).

摘自 PFFile 上的 iOS 指南,https://parse.com/docs/ios_guide#files/iOS

Reference answer from here, https://stackoverflow.com/a/16729142/1603234

在您的例子中,10485760 字节意味着 10.48576 兆字节。这是最大文件大小。

如何获取文件大小?

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:yourFilePath error:nil];
unsigned long long fileSize = [attributes fileSize]; // result would be in bytes

if(fileSize <= 10485760) {
    //you can continue for upload.
}else{
   //file size exceeding, can't upload.
}

然而,这是静态的,不可暗示,因为如果 PARSE 会改变主意并允许上传双倍大小的文件!

关于objective-c - 当 PFFile 太大时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25058014/

相关文章:

iPhone:学习资源 'instruments' ?

xcode - 未处理的 JS 异常 : undefined is not an object (evaluating 'u.View.propTypes.style' )

iphone - 调试构建和分发构建的 iPhone 项目build设置的主要区别是什么?

parse-platform - 通过 Parse.com 向 Windows Phone 8.1 发送原始通知

android - 如何使用 Parse.com 创建 ParseUsers 组?

android - 解析 Activity 未显示

ios - iOS-处理多个复选框

iOS:存储在安全区域中的 key 不支持解密

objective-c - 如何创建音频设备驱动程序来捕捉 Mac 正在播放的声音?

ios - 每个目标自定义 Mainstoryboard.strings