Get common application and device information in iOS development

Source: Internet
Author: User
Tags touch

1. Get Version number:

Version of the key in the plist file is "cfbundleshortversionstring", and on the App Store, the number is consistent, build in Plist key is "cfbundleversion", Represents the version number of the build, which should be increased by 1 after each builds.

[[[[NSBundle Mainbundle] infodictionary] objectforkey:@ "cfbundleshortversionstring"];

[[NSBundle mainbundle]objectforinfodictionarykey:@ "cfbundleshortversionstring"];

[[[[NSBundle Mainbundle] infodictionary] objectforkey:@ "cfbundleversion"];

2. Get mobile network status and carrier information

Import

coretelephony.framework

Introducing Header Files

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

#import <CoreTelephony/CTCarrier.h>

2.1 Get mobile phone network shape

<strong><span style= "FONT-SIZE:14PX;" >-(void) networktype{nsarray *subviews = [[[UIApplication Sharedapplication] valueforkey:@ "StatusBar"] ValueForK  
    ey:@ "Foregroundview"]subviews];  
    NSNumber *datanetworkitemview = nil; For (ID subview in subviews) {if ([Subview iskindofclass:[nsclassfromstring (@ "Uistatusbardatanetworkitemview") c  
            Lass]] {datanetworkitemview = Subview;  
        Break  
            switch ([[Datanetworkitemview valueforkey:@ Datanetworktype "]integervalue]) {case 0:  
            NSLog (@ "No WiFi or cellular");  
            infolabel.text=@ "no service";  
        Break  
            Case 1:nslog (@ "2G");  
            infolabel.text=@ "2G";  
        Break  
            Case 2:nslog (@ "3G");  
            infolabel.text=@ "3G";  
        Break  
            Case 3:nslog (@ "4G");  
            infolabel.text=@ "4G";  
        Break  
Case 4:            NSLog (@ "LTE");  
            infolabel.text=@ "LTE";  
        Break  
            Case 5:nslog (@ "Wifi");  
            infolabel.text=@ "Wifi";                
        Break  
    Default:break; }} </span></strong>


2.2 Get carrier information

<span style= "color: #333333;" >-(nsstring*) getoperatorname{  
    cttelephonynetworkinfo *telephonyinfo = [[Cttelephonynetworkinfo alloc] init];  
    Ctcarrier *carrier = [Telephonyinfo subscribercellularprovider];  
    NSString *currentcountry=[carrier Carriername];  
    NSLog (@ "[Carrier Isocountrycode]==%@,[carrier Allowsvoip]=%d,[carrier Mobilecountrycode=%@,[carrier mobilecountrycode]=%@ ", [Carrier Isocountrycode],[carrier allowsvoip],[carrier Mobilecountrycode],[carrier Mobilenetworkcode]);  
    return currentcountry;  
} </span>

3 Get the equipment common information

3.1 Mobile phone system: IPhone OS

nsstring* phoneversion = [[Uidevice currentdevice] systemversion];

3.2 Mobile Phone type: IPhone 6

+ (NSString *) iphonetype {struct Utsname systeminfo;
    
    Uname (&systeminfo);
    
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:nsasciistringencoding];
    
    if ([Platform isequaltostring:@ "iphone1,1"]) return @ "IPhone 2G";
    
    if ([Platform isequaltostring:@ "iphone1,2"]) return @ "IPhone 3G";
    
    if ([Platform isequaltostring:@ "iphone2,1"]) return @ "IPhone 3GS";
    
    if ([Platform isequaltostring:@ "iphone3,1"]) return @ "IPhone 4";
    
    if ([Platform isequaltostring:@ "iphone3,2"]) return @ "IPhone 4";
    
    if ([Platform isequaltostring:@ "iphone3,3"]) return @ "IPhone 4";
    
    if ([Platform isequaltostring:@ "iphone4,1"]) return @ "IPhone 4S";
    
    if ([Platform isequaltostring:@ "iphone5,1"]) return @ "IPhone 5";
    
    if ([Platform isequaltostring:@ "iphone5,2"]) return @ "IPhone 5";
    
    if ([Platform isequaltostring:@ "iphone5,3"]) return @ "IPhone 5c"; if ([Platform isequaltostring:@ IPhone5), 4 "]) return @" IPhone 5c ";
    
    if ([Platform isequaltostring:@ "iphone6,1"]) return @ "IPhone 5s";
    
    if ([Platform isequaltostring:@ "iphone6,2"]) return @ "IPhone 5s";
    
    if ([Platform isequaltostring:@ "iphone7,1"]) return @ "IPhone 6 Plus";
    
    if ([Platform isequaltostring:@ "iphone7,2"]) return @ "IPhone 6";
    
    if ([Platform isequaltostring:@ "iphone8,1"]) return @ "IPhone 6s";
    
    if ([Platform isequaltostring:@ "iphone8,2"]) return @ "IPhone 6s Plus";
    
    if ([Platform isequaltostring:@ "ipod1,1"]) return @ "ipod touch 1G";
    
    if ([Platform isequaltostring:@ "ipod2,1"]) return @ "ipod touch 2G";
    
    if ([Platform isequaltostring:@ "ipod3,1"]) return @ "ipod touch 3G";
    
    if ([Platform isequaltostring:@ "ipod4,1"]) return @ "ipod touch 4G";
    
    if ([Platform isequaltostring:@ "ipod5,1"]) return @ "ipod touch 5G";
    
    if ([Platform isequaltostring:@ "ipad1,1"]) return @ "IPad 1G"; if ([Platform isequaltostring:@ "ipad2,1"]) return @ "IPad2 ";
    
    if ([Platform isequaltostring:@ "ipad2,2"]) return @ "IPad 2";
    
    if ([Platform isequaltostring:@ "ipad2,3"]) return @ "IPad 2";
    
    if ([Platform isequaltostring:@ "ipad2,4"]) return @ "IPad 2";
    
    if ([Platform isequaltostring:@ "ipad2,5"]) return @ "IPad Mini 1G";
    
    if ([Platform isequaltostring:@ "ipad2,6"]) return @ "IPad Mini 1G";
    
    if ([Platform isequaltostring:@ "ipad2,7"]) return @ "IPad Mini 1G";
    
    if ([Platform isequaltostring:@ "ipad3,1"]) return @ "IPad 3";
    
    if ([Platform isequaltostring:@ "ipad3,2"]) return @ "IPad 3";
    
    if ([Platform isequaltostring:@ "ipad3,3"]) return @ "IPad 3";
    
    if ([Platform isequaltostring:@ "ipad3,4"]) return @ "IPad 4";
    
    if ([Platform isequaltostring:@ "ipad3,5"]) return @ "IPad 4";
    
    if ([Platform isequaltostring:@ "ipad3,6"]) return @ "IPad 4";
    
    if ([Platform isequaltostring:@ "ipad4,1"]) return @ "IPad Air";
    
   if ([Platform isequaltostring:@ "ipad4,2"]) return @ "IPad Air"; if ([Platform isequaltostring:@ "ipad4,3"]) return @ "IPad Air";
    
    if ([Platform isequaltostring:@ "ipad4,4"]) return @ "IPad Mini 2G";
    
    if ([Platform isequaltostring:@ "ipad4,5"]) return @ "IPad Mini 2G";
    
    if ([Platform isequaltostring:@ "ipad4,6"]) return @ "IPad Mini 2G";
    
    if ([Platform isequaltostring:@ "i386"]) return @ "IPhone Simulator";
    
    if ([Platform isequaltostring:@ "x86_64"]) return @ "IPhone Simulator";
    
return platform;
 }
3.3 Mobile System version: 9.1

NSString * Iponem = [[Uidevice currentdevice] systemname];
3.4 Cell Phone battery charge
CGFloat Batterylevel=[[uidevicecurrentdevice]batterylevel];





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.