#include <sys/> #include <sys/> //Get the device model+ (NSString *)getCurrentDeviceModel { int mib[2]; size_t len; charchar *machine; mib[0] = CTL_HW; mib[1] = HW_MACHINE; sysctl(mib, 2, NULL, &len, NULL, 0); machine = malloc(len); sysctl(mib, 2, machine, &len, NULL, 0); NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding]; free(machine); // iPhone if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone2G"; if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone3G"; if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone3GS"; if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone4"; if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone4"; if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone4"; if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone4S"; if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone5"; if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone5"; if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone5c"; if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone5c"; if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone5s"; if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone5s"; if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone6"; if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone6Plus"; if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone6s"; if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone6sPlus"; if ([platform isEqualToString:@"iPhone8,3"]) return @"iPhoneSE"; if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhoneSE"; if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone7"; if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone7Plus"; //iPod Touch if ([platform isEqualToString:@"iPod1,1"]) return @"iPodTouch"; if ([platform isEqualToString:@"iPod2,1"]) return @"iPodTouch2G"; if ([platform isEqualToString:@"iPod3,1"]) return @"iPodTouch3G"; if ([platform isEqualToString:@"iPod4,1"]) return @"iPodTouch4G"; if ([platform isEqualToString:@"iPod5,1"]) return @"iPodTouch5G"; if ([platform isEqualToString:@"iPod7,1"]) return @"iPodTouch6G"; //iPad if ([platform isEqualToString:@"iPad1,1"]) return @"iPad"; if ([platform isEqualToString:@"iPad2,1"]) return @"iPad2"; if ([platform isEqualToString:@"iPad2,2"]) return @"iPad2"; if ([platform isEqualToString:@"iPad2,3"]) return @"iPad2"; if ([platform isEqualToString:@"iPad2,4"]) return @"iPad2"; if ([platform isEqualToString:@"iPad3,1"]) return @"iPad3"; if ([platform isEqualToString:@"iPad3,2"]) return @"iPad3"; if ([platform isEqualToString:@"iPad3,3"]) return @"iPad3"; if ([platform isEqualToString:@"iPad3,4"]) return @"iPad4"; if ([platform isEqualToString:@"iPad3,5"]) return @"iPad4"; if ([platform isEqualToString:@"iPad3,6"]) return @"iPad4"; //iPad Air if ([platform isEqualToString:@"iPad4,1"]) return @"iPadAir"; if ([platform isEqualToString:@"iPad4,2"]) return @"iPadAir"; if ([platform isEqualToString:@"iPad4,3"]) return @"iPadAir"; if ([platform isEqualToString:@"iPad5,3"]) return @"iPadAir2"; if ([platform isEqualToString:@"iPad5,4"]) return @"iPadAir2"; //iPad mini if ([platform isEqualToString:@"iPad2,5"]) return @"iPadmini1G"; if ([platform isEqualToString:@"iPad2,6"]) return @"iPadmini1G"; if ([platform isEqualToString:@"iPad2,7"]) return @"iPadmini1G"; if ([platform isEqualToString:@"iPad4,4"]) return @"iPadmini2"; if ([platform isEqualToString:@"iPad4,5"]) return @"iPadmini2"; if ([platform isEqualToString:@"iPad4,6"]) return @"iPadmini2"; if ([platform isEqualToString:@"iPad4,7"]) return @"iPadmini3"; if ([platform isEqualToString:@"iPad4,8"]) return @"iPadmini3"; if ([platform isEqualToString:@"iPad4,9"]) return @"iPadmini3"; if ([platform isEqualToString:@"iPad5,1"]) return @"iPadmini4"; if ([platform isEqualToString:@"iPad5,2"]) return @"iPadmini4"; if ([platform isEqualToString:@"i386"]) return @"iPhoneSimulator"; if ([platform isEqualToString:@"x86_64"]) return @"iPhoneSimulator"; return platform; }
Obtain a summary of equipment information
1. Obtain device information
UIDevice *device = [[UIDevice alloc] int]; NSString *name = ; //Get the name of the device ownerNSString *model = ; //Get the device categoryNSString *type = ; //Get localized versionNSString *systemName = ; //Get the currently running systemNSString *systemVersion = ;//Get the current system version
2. Get the unique identifier of the device
NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
3. Create a random identifier for the system
(NSString*) createUUID { NSString *id = [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"]; //Get the value marked "UUID"if(id == nil) { if([[[UIDevice currentDevice] systemVersion] floatValue] > 6.0) { NSString *identifierNumber = [[NSUUID UUID] UUIDString]; //Api that can be used after ios 6.0[[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"]; //Save as UUID[[NSUserDefaults standardUserDefaults] synchronize]; } else{ CFUUIDRef uuid = CFUUIDCreate(NULL); CFStringRef uuidString = CFUUIDCreateString(NULL, uuid); //Api used before ios6.0NSString *identifierNumber = [NSString stringWithFormat:@"%@", uuidString]; [[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"]; [[NSUserDefaults standardUserDefaults] synchronize]; CFRelease(uuidString); CFRelease(uuid); } return [[NSUserDefaults standardUserDefaults] objectForKey@"UUID"]; } return id; }
4. Get information about the current screen resolution
CGRect rect = [[UIScreen mainScreen] bounds]; CGFloat scale = [[UIScreen mainScreen].scale]; CGFloat width = * scale; CGFloat height = * scale;
5. Obtain operator information
You need to import the header file first
#import <CoreTelephony/> #import <CoreTelephony/>
Create an object
CCTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
Get the name of the runner
CTCarrier *carrier = [info subscriberCellularProvider]; NSString *mCarrier = [NSString stringWithFormat:@"%@",[carrier carrierName]];
Get the current network type
After ios7, you can obtain it in the following way. Convenient and of many types
NSString *mConnectType = [[NSString alloc] initWithFormat:@"%@",];
The types are as follows:
CTRadioAccessTechnologyGPRS // Between 2G and 3G, also called 2.5G, excessive technologyCTRadioAccessTechnologyEdge //EDGE is the transition from GPRS to third-generation mobile communications. EDGE is commonly known as 2.75GCTRadioAccessTechnologyWCDMA CTRadioAccessTechnologyHSDPA //Also known as 3.5G (3?G)CTRadioAccessTechnologyHSUPA //Excessive technology from 3G to 4GCTRadioAccessTechnologyCDMA1x //3G CTRadioAccessTechnologyCDMAEVDORev0 //3G standardCTRadioAccessTechnologyCDMAEVDORevA CTRadioAccessTechnologyCDMAEVDORevB CTRadioAccessTechnologyeHRPD // A 3G to 4G evolution technology used by telecommunications, 3.75GCTRadioAccessTechnologyLTE //near4G
Before ios7, apple provided us with Reachability to obtain.
First, import and add the downloaded and added to the project
Reachability *reach = [Reachability reachabilityWithHostName:@""]; switch([reach currentReachabilityStatus]) { case NotReachable: //Not connected//do something break; case ReachableViaWiFi: //Connect via wifi//do something break; case ReachableViaWWAN: //Connect through GPRS//do something break; default: <span style="white-space:pre"> </span>//Unknown situation//do something break; }
6. Obtain the strength of the current signal
This does not seem to be given an official API, but some people on the Internet say that it can be implemented using a private API, but it cannot pass the appStore audit. The method is as follows:
Use dynamic libraries under Linux to explicitly call API functions. Include the header file first #import <>
(int) getSignalLevel { voidvoid *libHandle = dlopen("/System/Library/Frameworks//CoreTelephony",RTLD_LAZY);//Get the library handleint (*CTGetSignalStrength)(); //Define a function pointer that matches the function to be retrievedCTGetSignalStrength = (int(*)())dlsym(libHandle,"CTGetSignalStrength"); //Get the function with the specified name if(CTGetSignalStrength == NULL) return -1; else{ int level = CTGetSignalStrength(); dlclose(libHandle); //Remember to close the libraryreturn level } }
7. Equipment vibration
You need to add AudioToolbox framework to import the header file #import <AudioToolbox/>
Add code where vibration is needed:
AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate) ;
But it seems that this does not support incoming vibration time and mode, so please control it yourself.
8. Obtain battery related information
@implementation BatterMonitor //Get the current state of the battery, there are 4 states in total-(NSString*) getBatteryState { UIDevice *device = [UIDevice currentDevice]; if ( == UIDeviceBatteryStateUnknown) { return @"UnKnow"; }else if ( == UIDeviceBatteryStateUnplugged){ return @"Unplugged"; }else if ( == UIDeviceBatteryStateCharging){ return @"Charging"; }else if ( == UIDeviceBatteryStateFull){ return @"Full"; } return nil; } //Get the power level, 0.00~1.00-(float) getBatteryLevel { return [UIDevice currentDevice].batteryLevel; } -(void) getBatteryInfo { NSString *state = getBatteryState(); float level = getBatteryLevel()*100.0; //yourControlFunc(state, level); //How to deal with it after you get the power information you want to implement} //Open the monitoring of power and battery status, similar to the timer function-(void) didLoad { [[UIDevice currentDevice] setBatteryMonitoringEnable:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryStateDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryLevelDidChangeNotification object:nil]; [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(getBatteryInfo:) userInfo:nil repeats:YES]; } @end
9. Open a web page in the app
This is relatively simple, just use the provided interface openURL.
NSString *url = @"" [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
10. Open another app in the app
Opening another app can still be achieved through openURL. But there are two situations. The first is to launch built-in applications, general phone, browser, text messages and
Mail can be called directly and added parameters, such as
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@"]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];
The second case is to open the app you developed yourself, and in this case, you need to register a URL protocol for the app you are about to open. This can be registered in the project's file.
The main operations are:
Step1. Right-click and select "Add Row"
Step2. Select "URL types" for Key value
Step3. Open "Item 0" and add a URL identifier to the key. Can be any value, but it is recommended to use "anti-domain name" (e.g. "").
Step4. Add another line under "Item 0".
Step5. Select "URL Schemes" as the Key.
Step6. Enter your URL protocol name (for example, "testHello://" should be written as "testHello"). If necessary, you can join multiple protocols here.
In fact, only URL Schemes is needed when opening, and URL identifier is optional. If you need to transfer parameters, you can add your parameters at URL Schemes://. The format is similar to the delivery parameters of web development. (Or the parameters added by URL Schemes://URL identifier@) The key is to define the processing method with the receiving parameter party. Then add the code where you need to open:
NSString *url = @"Path to URL Schemes" [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
The above is the information about iOS acquisition of current device models and other information, including iPhone7 and iPhone7P, I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!