Suppose you don't want the IPhone to enter the lock screen standby when the app executes. Add the following line of code to
[[UIApplication sharedapplication] setidletimerdisabled:yes];
By the way, learning the next uiapplication.
The iphone application is initiated by main function main, which is responsible for invokingUiapplicationmainfunction, the form of the function, as seen in the following:
Align Uiapplicationmain, option+ mouse click. You can view it.
So what exactly does the Uiapplicationmain function do? This function is mainly responsible for three things:
1) Initializes the application object from the given class name. That is, to initialize an instance of the UIApplication or subclass object, assuming that you are given nil here, the system defaults to the UIApplication class, which is primarily the class that controls and coordinates the execution of the application.
In a possible job, you can use the static method sharedapplication to get the handle of the application.
2) The class is trusted from the given application. Initializes an application to entrust. And the trust is set to the application of the trust, here is the assumption that the incoming number of nil, will call the function to ask the Info.plist file to find the main nib file. Gets the application entrusted.
3) Start the main event loop and begin receiving events.
Above is the work of the Uiapplicationmain function. The next question is the display of the application view and the control of the message. Here isuiapplicationThe responsibility of the (or subclass) object. This object mainly does the following several things:
1) is responsible for handling incoming user events and distributing event messages to the target object (sender, action) that should process the message.
2) Manage and control views. Contains rendering, control behavior, current display view, and so on.
3) The object has an application-entrusted object. When there are important events in the life cycle that can include system events or life cycle control events. The application notifies the object.
For example, application startup, insufficient memory, or application end, etc., when these events occur, the application is entrusted to respond.
With the above analysis, it is possible to know that uiapplication is a black box for developers and it can be. As a result of all the operations, it can be entrusted to help us complete. It just needs to maintain something that cannot be changed in the back. such as event message distribution and delivery, sending an event processing request to a delegate, and so on, for example, the application loading process is complete. It sends a message to the delegate, which is then entrusted to implement the developer's desired action in the Applicationdidfinishlanching trust function. When you create an application with Xcode, an application commit class is implemented by default. And for the loaded view. There is a view-related commit class to handle the life events of the view loading process.
Here are some of the main things that you can do:
controlling the behavior of an application1,-(void) Applicationwillresignactive: (uiapplication *) ApplicationDescription: When an application is about to be executed in an inactive state during this period. The application does not receive messages or events. For example, the phone.2,-(void) Applicationdidbecomeactive: (uiapplication *) ApplicationDescription: When the application executes in the active state, this is exactly the opposite of the method above3,-(void) Applicationdidenterbackground: (uiapplication *) ApplicationDescription: Called when the program is pushed to the background. So to set the background to continue execution, you can set it in this function4,-(void) Applicationwillenterforeground: (uiapplication *) Application Description: Called when the program is going back to the foreground from the background, which is exactly the opposite of the method above.
5,-(void) Applicationwillterminate: (uiapplication *) Application Description: When the program is about to exit is called, it is generally used to save data and some cleanup work before exiting. This is required to set the Uiapplicationexitsonsuspend key value.
6,-(void) applicationdidreceivememorywarning: (uiapplication *) ApplicationDescription: The iphone device has only a limited amount of memory, assuming that the application is assigned too much memory that the operating system terminates the execution of the application and executes this method before terminating. Usually be able to do a memory cleanup here to prevent the program from being terminated7,-(void) Applicationsignificanttimechange: (uiapplication*) ApplicationDescription: Executes when the system time has changed8,-(void) applicationdidfinishlaunching: (uiapplication*) ApplicationDescription: Executes when the program is loaded9,-(void) application: (uiapplication) Application Willchangestatusbarframe: (cgrect) NewstatusbarframeDescription: Executes when the StatusBar box is going to change10,-(void) application: (uiapplication*) application willchangestatusbarorientation:(uiinterfaceorientation) newstatusbarorientationDuration: (nstimeinterval) DurationDescription: Executed when the StatusBar box direction is going to change11,-(BOOL) Application: (uiapplication*) Application Handleopenurl: (nsurl*) URLDescription: When executing via URL12,-(void) application: (uiapplication*) Application didchangestatusbarorientation: (uiinterfaceorientation) OldstatusbarorientationDescription: Executes when the StatusBar box direction changes13,-(void) application: (uiapplication*) Application Didchangesetstatusbarframe: (cgrect) OldstatusbarframeDescription: Executes when the StatusBar box changes
Applications in the iphone are very easy to be disturbed, such as an incoming call may cause the application to lose focus, assuming that the call is answered, then the application goes to the background.
There are so many other similar events that cause the iphone application to lose focus and call the Applicationwillresignactive () method of the entrusted class before the application loses focus. The Applicationdidbecomeactive () method is called when the application gets to the focus again.
For example, when executing an application, the lock screen invokes the Applicationwillresignactive () method of the entrusted class. And when the screen is unlocked. The Applicationdidbecomeactive () method is called again.
Another very important method is applicationdidreceivememorywarning (), because the iphone device has only limited memory. If the application is assigned too much memory, the operating system terminates execution of the application. But before terminating the operating system warns the application by first invoking the Applicationdidreceivememorywarning () method of the entrusted class. After UIApplication receives this event, it passes it to the applicationdidreceivememorywarning () method of the entrusted class, in which the delegate class is able to release memory operations to prevent the operating system from forcing the application to terminate execution.
Here are some of the features of this class:1. Set the number icon on the icon//Set the digital icon on the main interface icon, introduced in 2.0. Default is 0[UIApplication sharedapplication].applicationiconbadgenumber = 4;2. Whether the Redo,undo action is supported when setting the shake gesture//Shake gesture, whether the redo undo operation is supported. //3.0 introduced later, default Yes[uiapplication sharedapplication].applicationsupportsshaketoedit =yes;3. Infer Program Execution Status//Infer program execution status. Introduced after the 2.0 /*uiapplicationstateactive,uiapplicationstateinactive,Uiapplicationstatebackground */if ([uiapplication sharedapplication].applicationstate ==uiapplicationstateinactive) {NSLog (@ "program in execution State"); }4. Prevent the screen from darkening into hibernation//Prevent the screen from darkening. Use sparingly, default is no 2.0[uiapplication sharedapplication].idletimerdisabled =yes;Use this feature sparingly, due to the very power consumption. 5. Show Networking Status//Display Networking Tag 2.0[uiapplication sharedapplication].networkactivityindicatorvisible =yes;6. Show an address on the mapnsstring* addresstext [email protected] "1 Infinite Loop, Cupertino, CA 95014";//URL encode the spacesAddresstext = [Addresstext stringbyaddingpercentescapesusingencoding:nsasciistringencoding];nsstring* urltext = [NSString stringwithformat:@ "http://maps.google.com/maps?q=%@", Addresstext];[[UIApplication Sharedapplication]openurl:[nsurlurlwithstring:urltext]];7. Send an emailnsstring *recipients [email protected] "Mailto:[email protected][email protected],[email protected]& Subject=hello from california! ";nsstring *body [email protected] "&body=it is raining in sunny california!";nsstring *email = [NSString stringwithformat:@ "%@%@", recipients, body];email = [email stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];[[UIApplication Sharedapplication]openurl:[nsurlurlwithstring:email]];8. Call a number//Call Google 411[[UIApplication sharedapplication]openurl:[nsurlurlwithstring:@ "tel://8004664411"];9. Send SMS//Text to Google SMS[[UIApplication sharedapplication]openurl:[nsurlurlwithstring:@ "sms://466453"];10. Open a URL//Lanuch any IPhone developers fav site[[UIApplication sharedapplication]openurl:[nsurlurlwithstring:@ "http://itunesconnect.apple.com"];
iOS development-Do not enter standby (screen to stay awake)---uiapplication learning