IOS development-how to get the total device capacity and available capacity network operator 3g/wifi determine the mobile phone model

Source: Internet
Author: User

IOS development-how to get the total device capacity and available capacity network operator 3g/wifi determine the mobile phone model

This is a good example of getting mobile phone capacity recently developed by lingge.

// Hard disk capacity

-(Float) getTotalDiskSpace

{

Float totalSpace;

NSError * error;

NSDictionary * infoDic = [[nsfilemanagerdefamanager manager] attributesOfFileSystemForPath: [selfgetHomeDirectory] error: & error];

If (infoDic ){

NSNumber * fileSystemSizeInBytes = [infoDicobjectForKey: NSFileSystemSize];

TotalSpace = [fileSystemSizeInBytes floatValue]/1024366f/1024366f/1024366f;

Return totalSpace;

} Else {

NSLog (@ "Error Obtaining System Memory Info: Domain =%@, Code = % ld", [errordomain], (long) [errorcode]);

Return 0;

}

}

-(NSString *) getHomeDirectory

{

NSString * homePath = NSHomeDirectory ();

Return homePath;

}


/*

How to obtain the total capacity and available capacity of a device

*/

+ (NSNumber *) totalDiskSpace

{

NSDictionary * fattributes = [[nsfilemanagerdefamanager manager] attributesOfFileSystemForPath: NSHomeDirectory () error: nil];

Return [fattributes objectForKey: NSFileSystemSize];

}

+ (NSNumber *) freeDiskSpace

{

NSDictionary * fattributes = [[nsfilemanagerdefamanager manager] attributesOfFileSystemForPath: NSHomeDirectory () error: nil];

Return [fattributes objectForKey: NSFileSystemFreeSize];

}




// The Mobile Phone model (which is different from the one obtained by the system. This is for iPhone 5, iPhone 4, and iPhone 6 ).

# Import "sys/utsname. h"

+ (NSString *) deviceString

{

// # Import "sys/utsname. h"

Struct utsname systemInfo;

Uname (& systemInfo );

NSString * deviceString = [NSStringstringWithCString: systemInfo. machineencoding: NSUTF8StringEncoding];

If ([deviceString isEqualToString: @ "iPhone1, 1"]) return @ "iPhone 1G ";

If ([deviceString isEqualToString: @ "iPhone1, 2"]) return @ "iPhone 3G ";

If ([deviceString isEqualToString: @ "iPhone2, 1"]) return @ "iPhone 3GS ";

If ([deviceString isEqualToString: @ "iPhone3, 1"]) return @ "iPhone 4 ";

If ([deviceString isEqualToString: @ "iPhone4, 1"]) return @ "iPhone 4 S ";

If ([deviceString isEqualToString: @ "iPhone5, 2"]) return @ "iPhone 5 ";

If ([deviceStringisEqualToString: @ "iPhone3, 2"]) return @ "Verizon iPhone 4 ";

If ([deviceString isEqualToString: @ "iPod1, 1"]) return @ "iPod Touch 1G ";

If ([deviceString isEqualToString: @ "iPod2, 1"]) return @ "iPod Touch 2G ";

If ([deviceString isEqualToString: @ "iPod3, 1"]) return @ "iPod Touch 3G ";

If ([deviceString isEqualToString: @ "iPod4, 1"]) return @ "iPod Touch 4G ";

If ([deviceString isEqualToString: @ "iPad1, 1"]) return @ "iPad ";

If ([deviceString isEqualToString: @ "iPad2, 1"]) return @ "iPad 2 (WiFi )";

If ([deviceString isEqualToString: @ "iPad2, 2"]) return @ "iPad 2 (GSM )";

If ([deviceString isEqualToString: @ "iPad2, 3"]) return @ "iPad 2 (CDMA )";

If ([deviceString isEqualToString: @ "i386"]) return @ "Simulator ";

If ([deviceString isEqualToString: @ "x86_64"]) return @ "Simulator ";

NSLog (@ "NOTE: Unknown device type: % @", deviceString );

Return deviceString;

}


// Determine whether to import 3G or Wi-Fi # import "Reachability. h"

Reachability * reachbility = [ReachabilityreachabilityWithHostName: @ "www.baidu.com"]; NetworkStatus status = [reachbility currentReachabilityStatus];

NSString * netStr;

// Use a Wi-Fi network connection

If (status = ReachableViaWiFi)

{

NetStr = @ "wifi ";

// [[NSUserDefaults standardUserDefaults] setObject: netStr forKey: @ "network"];

}

Else if (status = ReachableViaWWAN)

{

NetStr = @ "3g ";

// [[NSUserDefaults standardUserDefaults] setObject: netStr forKey: @ "network"];

}

NSLog (@ "network is: % @", netStr );

/* For Carrier information, use the CTTelephonyNetworkInfo and CTCarrier types in CoreTelephony Framework. These are available after iOS 4.0.

Import required headers:

# Import

# Import

How can I determine the operator of the current network?

*/

// Identifies the carrier of the network used by the device.

-(NSString *) checkCarrier


{

NSString * ret = [[NSStringalloc] init];

CTTelephonyNetworkInfo * info = [[CTTelephonyNetworkInfoalloc] init];

CTCarrier * carrier = [infosubscriberCellularProvider];

If (carrier = nil ){

Return @ "0 ";

}

NSString * code = [carrier worker enetworkcode];

If ([code isEqual: @ ""]) {

Return @ "0 ";

}

If ([codeisEqualToString: @ "00"] | [codeisEqualToString: @ "02"] | [codeisEqualToString: @ "07"]) {

Ret = @ "mobile ";

}

If ([codeisEqualToString: @ "01"] | [codeisEqualToString: @ "06"]) {

Ret = @ "Unicom ";

}

If ([codeisEqualToString: @ "03"] | [codeisEqualToString: @ "05"]) {

Ret = @ "Telecom ";;

}

NSLog (@ "% @", ret );

Return ret;

}





Related Article

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.