iOS summary _ios frequently used methods collection, call system phone, device differentiate, never lock screen in app

Source: Internet
Author: User

function of calling system call

Phone calls are only supported by the iphone, and the corresponding button for other devices should be disabled.

Call the system phone call function directly, can't go back to the application after hanging up the phone

[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://8004664411"];


Before calling the system phone call function to give a hint, hang up the phone can go back to the application

[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "telprompt://8004664411"];


Similarly, can also call system map, SMS and other functions

OpenURL can help you execute maps,sms,browser,phone and even other applications. This is a piece of code that I often need to use in the development of my iphone , which is only one line.


Ways to differentiate device types

Infer whether it's an iphone or an ipad
With [Uidevice Currentdevice].model, this return is a nsstring, you can do for example the following inference to know whether the device is an ipad or an iPhone.

if ([Uidevice currentdevice].model rangeofstring:@ "IPad"].location! = Nsnotfound)

NSLog (@ "This was an ipad!");


With the Ui_user_interface_idiom () method, this is a system-defined macro. The usage is also very easy.

if (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)

NSLog (@ "This was an ipad!");


Infer device type and model

-(nsstring*) dodeviceplatform{size_t size;    int NR = Sysctlbyname ("Hw.machine", NULL, &size, NULL, 0);    Char *machine = (char *) malloc (size);    NR = Sysctlbyname ("Hw.machine", Machine, &size, NULL, 0);    NSString *platform = [NSString stringwithcstring:machine encoding:nsutf8stringencoding];        Free (machine);            if ([Platform isequaltostring:@ "iphone1,1"]) {platform = @ "IPhone";            } else if ([Platform isequaltostring:@ "iphone1,2"]) {platform = @ "IPhone 3G";            } else if ([Platform isequaltostring:@ "iphone2,1"]) {platform = @ "IPhone 3GS"; } else if ([Platform isequaltostring:@ "iphone3,1"]| | [Platform isequaltostring:@ "iphone3,2"]| | [Platform isequaltostring:@ "iphone3,3"])            {platform = @ "IPhone 4";            } else if ([Platform isequaltostring:@ "iphone4,1"]) {platform = @ "IPhone 4S"; } else if ([Platform isequaltostring:@ "iphone5,1"]| | [Platform IsEqualtostring:@ "iphone5,2"]) {platform = @ "IPhone 5"; }else if ([Platform isequaltostring:@ "iphone5,3"]| | [Platform isequaltostring:@ "iphone5,4"])            {platform = @ "IPhone 5C"; }else if ([Platform isequaltostring:@ "iphone6,2"]| | [Platform isequaltostring:@ "iphone6,1"])            {platform = @ "IPhone 5S";            }else if ([Platform isequaltostring:@ "ipod4,1"]) {platform = @ "IPod touch 4";            }else if ([Platform isequaltostring:@ "ipod5,1"]) {platform = @ "IPod Touch 5";            }else if ([Platform isequaltostring:@ "ipod3,1"]) {platform = @ "IPod touch 3";            }else if ([Platform isequaltostring:@ "ipod2,1"]) {platform = @ "IPod touch 2";            }else if ([Platform isequaltostring:@ "ipod1,1"]) {platform = @ "IPod touch"; } else if ([Platform isequaltostring:@ "ipad3,2"]| | [Platform isequaltostring:@ "ipad3,1"]) {PLAtform = @ "IPad 3"; } else if ([Platform isequaltostring:@ "ipad2,2"]| | [Platform isequaltostring:@ "ipad2,1"]| | [Platform isequaltostring:@ "ipad2,3"]| | [Platform isequaltostring:@ "ipad2,4"])            {platform = @ "IPad 2";            }else if ([Platform isequaltostring:@ "ipad1,1"]) {platform = @ "IPad 1"; }else if ([Platform isequaltostring:@ "ipad2,5"]| | [Platform isequaltostring:@ "ipad2,6"]| | [Platform isequaltostring:@ "ipad2,7"])            {platform = @ "ipad Mini"; } else if ([Platform isequaltostring:@ "ipad3,3"]| | [Platform isequaltostring:@ "ipad3,4"]| | [Platform isequaltostring:@ "ipad3,5"]| | [Platform isequaltostring:@ "ipad3,6"])            {platform = @ "ipad 3"; } return platform;}


Never lock the screen while the device is executing the program

[[uiapplicationsharedapplication]setidletimerdisabled : YES ];


Maybe update ...


iOS summarizes _ios frequently used methods collection, call system phone, device differentiation, never lock screen in app

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.