2012-05-18 47 views
-2

可能重複:
How to get information about free memory and running processes in an App Store approved app? (Yes, there is one!)如何在IOS中獲得可用內存?

如何在IOS獲取可用的內存?我不知道..

我GOOGLE了,後來我才知道我怎樣才能得到物理內存,用戶記憶和使用MEM,在VM免費MEM。

但是。內存大小與Settings - > General - > About - > Avaliable不同。

我想知道在設置「]可」。

祝您有愉快的一天。

+0

我想你的意思是「可用的存儲」 - http://stackoverflow.com/a/8036586/603256 – JamesHalsall

+0

請問以下爲你工作? http://stackoverflow.com/questions/5012886/knowing-available-ram-on-an-ios-device –

+0

哦。我懂了。那就對了。 「可用存儲」......但還有一個問題。我在方法背後使用了「可用存儲」,但有點不同..總是200MB或160MB。爲什麼..?幫我 .. – alex

回答

1

發現這個在這裏幾個月前記不起誰最初發布。這是你想要的?

- (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 = %@", [error domain], [error code]); 
} 

return totalFreeSpace; 
} 
相關問題