我正在尋找iPhone應用程序的大小以及框架,但我沒有找到一個方法如何做到這一點。任何人都可以爲我提供這樣的代碼?我得到的代碼在運行時查找我的應用程序的當前內存使用情況。如何以編程方式查找我iphone應用程序的大小?
1
A
回答
1
NSString *folderPath = [[NSBundle mainBundle] bundlePath];
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileName;
unsigned long long int fileSize = 0;
while (fileName = [filesEnumerator nextObject]) {
NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES];
fileSize += [fileDictionary fileSize];
}
NSLog(@"App size : %lld",fileSize);
0
如果有人還在尋找答案,那麼:請注意fileAttributesAtPath方法depriciated所以使用attributesOfItemAtPath方法
例子:
//get full pathname of bundle directory
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
//get paths of all of the contained subdirectories
NSArray *bundleArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:bundlePath error:nil];
//to access each object in array
NSEnumerator *filesEnumerator = [bundleArray objectEnumerator];
NSString *fileName;
unsigned long long int fileSize = 0;
NSError *error = nil;
//return next object from enumerator
while (fileName = [filesEnumerator nextObject])
{
NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:[bundlePath stringByAppendingPathComponent:fileName] error:&error];
fileSize += [fileDictionary fileSize];
}
//converts a byte count value into a textual representation that is formatted with the appropriate byte modifier (KB, MB, GB and so on)
NSString *folderSizeStr = [NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleMemory];
NSLog(@"App size (bundle size): %@ \n\n\n",folderSizeStr);
0
斯威夫特答案 - SWIFT 3.x
let bundlePath = Bundle.main.bundlePath
let bundleArray = FileManager.default.subpaths(atPath: bundlePath)
var fileSize : UInt64 = 0
for file in bundleArray! {
do {
let attr = try FileManager.default.attributesOfItem(atPath: bundlePath + "/" + file)
let xfileSize = attr[FileAttributeKey.size] as? UInt64 ?? 0
fileSize = fileSize + xfileSize
} catch {
}
}
let folderSize = ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .memory)
print("App size (bundle size): \(folderSize)")//xx MB
哪樣讓你捆綁的應用程序的大小 -
/用戶/ MyLaptop /庫/開發商/ CoreSimulator /設備/ DB7032C9-7CE2-42A9-83D1-59E2D2C5C361 /數據/集裝箱/包/ Application/CC808040-2F18-4B35-A912-591BD0C7DCD9/MyApp.app
相關問題
- 1. 如何以編程方式查找當前LOH的大小?
- 2. 如何以編程方式查找Azure實例角色大小?
- 3. 我的iPhone應用程序的最小應用程序大小?
- 4. 如何以編程方式退出iPhone應用程序?
- 5. 以編程方式檢查fixnum大小
- 6. 以編程方式使用me.com「查找我的iPhone」
- 7. 如何以編程方式查詢iphone應用程序的安裝信息?
- 8. 如何在android中以編程方式獲取應用程序的大小?
- 9. 如何以編程方式檢查我的android應用程序的可用堆大小?
- 10. 以編程方式查找iPhone應用程序標識符前綴
- 11. 如何以編程方式最小化/隱藏應用程序?
- 12. 如何以編程方式最小化iPad應用程序?
- 13. 如何在黑莓中以編程方式查找正在運行的應用程序大小?
- 14. IPhone應用程序大小
- 15. 如何以編程方式查找iphone設備的ip?
- 16. 如何找到MemoryCache的大小,最好以編程方式?
- 17. 如何以編程方式查找javac.exe?
- 18. 如何以編程方式確定我的桌面的大小?
- 19. 如何以編程方式查找谷歌應用程序實例
- 20. 如何在Swift中以編程方式獲取iPad/iPhone應用程序的大小
- 21. 以編程方式查找kafka主題大小
- 22. 有沒有任何應用程序可以查看iPhone應用程序大小的大小?
- 23. 如何以編程方式檢查Android上SMS消息大小
- 24. 以編程方式讓iPhone從應用程序中沉默?
- 25. 以編程方式打開設置應用程序(iPhone)
- 26. 可以通過編程方式關閉iphone應用程序
- 27. 以編程方式打開iphone日曆應用程序
- 28. 以編程方式創建Iphone應用程序vs Storyboard
- 29. 以編程方式卸載iPhone應用程序
- 30. iPhone:如何以編程方式查找應用程序的安裝日期和更新日期
爲什麼你需要知道這個?我在問,因爲我相信你正在嘗試做一些不需要的事情。另外,我不認爲這是可能的。 – dasdom 2012-07-31 06:45:10
相關:http://stackoverflow.com/questions/2188469/calculate-the-size-of-a-folder(只是指出它在你的應用程序包) – cobbal 2012-07-31 06:51:14
你想檢查多少內存正在用盡你的應用程序,然後你可以嘗試這個鏈接: - http://stackoverflow.com/questions/6641540/xcode-4-how-to-profile-memory-usage-performance-with-instruments – Leena 2012-07-31 06:54:13