How to obtain the code for the remaining disk space in iPhone development applications

Source: Internet
Author: User

IPhone DevelopmentHow to obtain surplus in an applicationDisk SpaceThe Code is the content to be introduced in this article, mainly to understandIphone DevelopmentRemaining ApplicationDisk Space. There is not much content, mainly through code. This code shows how to obtain the remaining disk space of the iPhone and all the disk space.

 
 
  1. #include <sys/param.h>      
  2. #include <sys/mount.h>   
  3. long long freeSpace() {   
  4.    struct statfs buf;   
  5.   long long freespace = -1;   
  6.     if(statfs("/", &buf) >= 0){   
  7.        freespace = (long long)buf.f_bsize * buf.f_bfree;   
  8.     }   
  9.       
  10.    return freespace;   
  11. }   
  12.  
  13. +(float)getTotalDiskSpaceInBytes {      
  14.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);      
  15.     struct statfs tStats;      
  16.     statfs([[paths lastObject] cString], &tStats);      
  17.     float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);      
  18.     return totalSpace;      
  19. }   

Summary:IPhone DevelopmentHow to obtain surplus in an applicationDisk SpaceThe content of the Code has been introduced. I hope this article will help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.