<p>結論としてはNSFileManagerのattributesOfFileSystemForPathを使用して値を取得する。ちなみに全体容量の値はiTunesで確認できる全体容量と同じものである。</p><!–more–><p>attributesOfFileSystemForPathはNSDictionaryに値を入れることになるのだが、その中にあるNSFileSystemFreeSizeは空き容量、NSFileSystemSizeは全体容量の値を持っている。</p><pre>NSString *path = NSHomeDirectory();NSNumber *allSize = nil;NSNumber *freeSize = nil;NSError *error = nil;NSDictionary *dict = [[NSFileManager defaultManager]attributesOfFileSystemForPath:path error:&error];allSize = [dict objectForKey:NSFileSystemSize]; / 使用容量freeSize = [dict objectForKey:NSFileSystemFreeSize]; / 空き容量NSLog(@"used:%.3f GB",[allSize floatValue]/1024/1024/1024);NSLog(@"free:%.3f GB",[freeSize floatValue]/1024/1024/1024);</pre><p>なお、全体容量と空き容量を取得するために、NSFileManagerのfileSystemAttributesAtPathを使用すると紹介している記事があるが、これは以前のiOSにおいて有効なものであり、現在は使えない。</p><ul> <li><a href="https://superdiszo.sakura.ne.jp/WP/?p=115" target="_blank">ボリュームの空き容量を取得する (DZ空間)</a></li> <li><a href="https://ip7.biz/wordpress/?p=420" target="_blank">iPhoneの空き容量を取得する (おいしいCocoaの飲み方)</a></li> <li><a href="https://stackoverflow.com/questions/1626139/how-do-you-find-how-much-disk-space-is-left-in-cocoa" target="_blank">How do you find how much disk space is left in Cocoa? (stackoverFlow)</a></li></ul>
Objective-CでiOSの全体容量と空き容量の取得
May 22, 2011
カテゴリ
タグ
- .NET (5)
- AAD (1)
- AfterEffects (1)
- Apache (1)
- Apple (1)
- Authenticator (1)
- Autodesk (3)
- aws (1)
- Azure (3)
- AzureFunctions (2)
- Blender (9)
- C (3)
- C++ (2)
- cyberduck (1)
- Dev Container (1)
- Docker (1)
- Emacs (10)
- FBX (1)
- Fire TV (1)
- Forge (1)
- Git (1)
- Go (3)
- Google (1)
- GPG (2)
- HoloLens (5)
- HoloLens2 (1)
- Houdini (1)
- HTML (1)
- Hugo (4)
- ime (1)
- iOS (4)
- ITS (2)
- javascript (4)
- Kaleidoscope (1)
- launchd (1)
- Linux (17)
- Liquid (4)
- LSP (1)
- macOS (42)
- Maya (13)
- MRTK (4)
- MySQL (3)
- Netlify (1)
- OpenGL (2)
- Org-Mode (4)
- Parallels (1)
- PGP (1)
- Programming (3)
- ProtocolBuffer (1)
- Python (3)
- R (3)
- Redmine (2)
- RenderMan (5)
- Ruby on Rails (2)
- rx (1)
- RxSwift (1)
- s3 (1)
- Sourcetrail (1)
- Subversion (1)
- Swift (7)
- Ubuntu (26)
- Unity (8)
- UnityHub (2)
- USD (6)
- UWP (1)
- VFX (8)
- Viewer3D.js (1)
- Visualization (1)
- VisualStudio (5)
- VSCode (3)
- VSIX (1)
- Web (9)
- Webビュー (1)
- Windows (11)
- WordPress (1)
- Xcode (12)
- オブジェクト指向 (3)
- おもちゃ (1)
- デザインパターン (3)
- マグカップ (1)
- 作品集 (1)
- 修理 (1)
- 健康 (2)
- 子ども (1)
- 思い出 (1)
- 映画 (2)
- 環境構築 (1)
- 統計学 (3)
- 認証 (1)
- 読書 (1)
- 過去記事インポート (281)
- 配線 (2)
- 開発環境 (10)