IOS device Information Retrieval

Source: Internet
Author: User

IOS device Information Retrieval
 
1. Get device information
UIDevice * device = [[UIDevice alloc] init];
NSString * name = device. name;
NSString * model = device. model; // device type, such as Apple or itouch
NSString * type = device. localizedModel; // obtain the local version.
NSString * systemName = device. systemName; // name of the currently running system
NSString * systemVersion = device. systemVersion; // obtain the current system version.



NSLog (@ % @-% @, name, model, type, systemName, systemVersion );
// IPhone Simulator-iPhone OS-8.1


2. Obtain the unique identifier (UDID) of the device)
NSString * identifier = [[UIDevice currentDevice] identifierForVendor] UUIDString];


3. Get the current screen resolution information
CGRect rect = [UIScreen mainScreen]. bounds;
CGFloat scale = [UIScreen mainScreen]. scale;
CGFloat width = rect. size. width * scale;
CGFloat height = rect. size. height * scale;


4. Obtain carrier Information
# Import
# Import


CTTelephonyNetworkInfo * info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier * carrier = [info subscriberCellularProvider];
NSString * mCarrier = [NSString stringWithFormat: % @, [carrier carrierName]; // obtain the carrier name

NSString * mConnectType = [NSString stringWithFormat: % @, info. currentRadioAccessTechnology]; // obtain the current network type


5. Add Vibration


# Import
AudioServicesPlayAlertSound (kSystemSoundID_Vibrate); // Add a vibration
However, it seems that this does not support the input of the vibration time and mode.


6. obtain information about the battery.
@ Implementation BatterMonitor
// Obtain the current Battery status. There are four statuses.
-(NSString *) getBatteryState {
UIDevice * device = [UIDevice currentDevice];
If (device. batteryState = UIDeviceBatteryStateUnknown ){
Return @ UnKnow;
} Else if (device. batteryState = UIDeviceBatteryStateUnplugged ){
Return @ Unplugged;
} Else if (device. batteryState = UIDeviceBatteryStateCharging ){
Return @ Charging;
} Else if (device. batteryState = UIDeviceBatteryStateFull ){
Return @ Full;
}
Return nil;
}
// Obtain 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); // write the information you want to implement and how to handle it after obtaining the Power Information
}


// Enable monitoring of power and battery status, similar to the timer function
-(Void) didLoad
{
[[UIDevice currentDevice] setBatteryMonitoringEnable: YES];
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (getBatteryInfo :) name: UIDeviceBatteryStateDidChangeNotification object: nil];
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (getBatteryInfo :) name: UIDeviceBatteryLevelDidChangeNotification object: nil];
[NSTimer scheduledTimerWithTimeInterval: 0.5f target: self selector: @ selector (getBatteryInfo :) userInfo: nil repeats: YES];
}
@ End


7. Open a webpage in the app
NSString * url = @ www.apple.com
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url];


8. Open another app in the app
You can use openURL to open another app. However, there are two cases.
The first is to start the built-in application. Generally, you can directly call and add parameters for phones, browsers, text messages, and emails. For example:


[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ tel: // 10086];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ mailto: // devprograms@apple.com];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ sms: // 10086];


The second case is to open your own developed app. In this case, you need to register a URL protocol for the app to be opened. This can be registered in the info. plist file of the project. The main operations are as follows:


Step1. right-click and select "Add Row"


Step2. select "URL types" for the Key value"


Step open "Item 0" and add a URL identifier for the key. It can be any value, but we recommend that you use "anti-domain name" (for example, "com. fcplayer. testHello ").


Step 4. Add a row under Item 0.


Step 5. Select "URL Schemes" as the Key.


Step 6. Enter Your URL protocol name (for example, "testHello: //" should be written as "testHello "). If necessary, you can add multiple protocols here.


In fact, you only need to URL Schemes when opening it. URL identifier is optional. If you want to transmit parameters, you can add your parameters in the URL Schemes: //. The format is similar to that of the webpage-developed transmission parameters. (Or URL Schemes: // URL identifier @ added parameter) the key is to define the processing method with the recipient parameter. Then add the Code where you want to open it:


NSString * url = @ URL Schemes path
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url];

 

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.