Browse Source

计算手机磁盘空余空间

harry 3 năm trước cách đây
mục cha
commit
da064b34ec
1 tập tin đã thay đổi với 34 bổ sung0 xóa
  1. 34 0
      BFCommonKit/Classes/BFUtility/PQBridgeObject.m

+ 34 - 0
BFCommonKit/Classes/BFUtility/PQBridgeObject.m

@@ -98,4 +98,38 @@ int32_t const CHUNK_SIZE = 8 * 1024;
     return [NSData dataWithBytes:(const void *)digestResult length:CC_MD5_DIGEST_LENGTH * sizeof(unsigned char)];
 }
 
+
+// 手机剩余空间
+- (CGFloat)getPhoneDiskFreeSize {
+
+    uint64_t totalSpace = 0;
+
+    uint64_t totalFreeSpace = 0;
+
+    NSError *error = nil;
+
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+
+    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
+
+    CGFloat s = 0;
+
+    if (dictionary.count) {
+
+        NSNumber *fileSystemSizeInBytes = dictionary[NSFileSystemSize];
+
+        NSNumber *freeFileSystemSizeInBytes = dictionary[NSFileSystemFreeSize];
+
+        totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
+
+        totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
+
+        s = totalFreeSpace/ (1024.0 * 1024.0);
+
+    }
+
+    return s;
+
+}
+
 @end