Reference: http://blog.csdn.net/decajes/article/details/41807977
Reference: http://zengrong.net/post/2152.htm
1. Get information about your device
Uidevice *device = [[Uidevice alloc] init];
NSString *name = device.name;
NSString *model = Device.model; Device type, such as Apple or itouch
NSString *type = Device.localizedmodel; Get localized version
NSString *systemname = device.systemname; Name of the current running system
NSString *systemversion = device.systemversion; Get the version of the current system
NSLog (@ "%@-%@-%@-%@-%@", name,model,type,systemname,systemversion);
IPhone simulator-iphone simulator-iphone Simulator-iphone OS-8.1
2. Obtain a unique identifier for the device (UDID)
NSString *identifier = [[[Uidevice Currentdevice] Identifierforvendor] uuidstring];
3. Get information about the current screen resolution
CGRect rect = [UIScreen mainscreen].bounds;
CGFloat scale = [UIScreen mainscreen].scale;
CGFloat width = rect.size.width * scale;
CGFloat height = rect.size.height * scale;
4. Access to carrier information
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
Cttelephonynetworkinfo *info = [[Cttelephonynetworkinfo alloc] init];
Ctcarrier *carrier = [info subscribercellularprovider];
NSString *mcarrier = [NSString stringwithformat:@ "%@", [carrier Carriername]]; Get the name of the carrier
NSString *mconnecttype = [NSString stringwithformat:@ "%@", info.currentradioaccesstechnology]; Get Current Network type
5. Add Vibration
#import <AudioToolbox/AudioToolbox.h>
Audioservicesplayalertsound (ksystemsoundid_vibrate); Add Vibration
But it seems that this does not support incoming vibration time and mode.
6. Get information about the battery
@implementation Battermonitor
Get the current status of the battery, there are 4 different states
-(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;
}
Get the level of power, 0.00~1.00
-(float) Getbatterylevel {
return [Uidevice Currentdevice].batterylevel;
}
-(void) Getbatteryinfo
{
NSString *state = Getbatterystate ();
Float level = Getbatterylevel () *100.0;
Yourcontrolfunc (state, level); Write what you want to do when you get the battery information.
}
Turn on monitoring of battery and battery status, like 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
7. Open a Web page in the app
NSString *url = @ "www.apple.com"
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:url]];
8. Open another app in the app
Opening another app is still possible with OpenURL. But there are two kinds of situations.
The first is to launch the built-in apps, general phone, browser, SMS and mail can call and add parameters directly, for example:
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://10086"];
[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "Mailto://[email protected]"];
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "sms://10086"];
The second scenario is to open the app you've developed, which is to register a URL protocol for the app you're about to open. This can be registered in the project's file info.plist. The main actions are:
Step1. Right-click to select "Add Row"
Step2. Key value Select "URL Types"
Step3. Open the Item 0″, and then add a URL identifier for the key. Can be any value, but it is recommended to use "anti-domain name" (for example, "Com.fcplayer.testHello").
Step4. Add a line under "Item 0".
Step5. Select "URL schemes" as key.
Step6. Enter your URL protocol name (for example "testhello://" should be written "Testhello"). If necessary, you can add multiple protocols here.
In fact, when opened only need URL schemes, URL identifier is optional. If you need to transfer parameters, you can add your parameters in the URL schemes://, the format and the Web page development of the transfer parameters are similar. (or the URL schemes://url [email protected] The parameters added) the key is to and receive parameters to define the way to handle. Then add the code where it needs to be opened:
NSString *url = @ "path to URL schemes"
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:url]];
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS Device Information Acquisition