0

如何检测 iPhone/iPad 设备上的总可用/空闲磁盘空间?

4

1 回答 1

2

我假设单击“完成”按钮会调用取消选择器;在这种情况下,您可以尝试您是否尝试实现委托方法:

 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
      [self dismissViewControllerAnimated:YES completion:^(void) {
           NSLog(@"Cancelled pick");
      };
 }

看起来你在打电话release——有什么理由不使用 ARC?

如果我不得不猜测,我会说也许警报解除实际上是在调用类似的东西

 [imagePicker.delegate imagePickerControllerDidCancel:imagePicker];

但它已经发布了,所以你会看到这个“锁定”问题。也许在调试器中单步执行并确保这些对象仍然存在。

编辑:

虽然它不能解决您的原始问题,但您可以在启动图像选择器之前检查可用空间,可能使用类似这样的内容,因此帖子建议:

- (uint64_t)freeDiskspace
 {
     uint64_t totalSpace = 0;
     uint64_t totalFreeSpace = 0;

     __autoreleasing NSError *error = nil;  
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
     NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  

     if (dictionary) {  
         NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];  
         NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
         totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
         totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
         NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
     } else {  
         NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %d", [error domain], [error code]);  
     }    

     return totalFreeSpace;
 }
于 2013-01-14T19:17:32.523 回答