Application hangs, restores, and Terminates-ios development

Source: Internet
Author: User
<span id="Label3"></p><span style="font-size: 14px; line-height: 21px;"><span style="font-size: 14px; line-height: 21px;">this article reprinted to http://justcoding.iteye.com/blog/1473350</span></span><p><p></p></p><p><p><strong>one, Hang Up</strong></p></p><p><p>When there is a phone coming in or lock screen, then your application will hang, at this time, uiapplicationdelegate delegate will be notified, call the Applicationwillresignactive method, you can override this method, do the work before the hang, For example, close the network and save the Data.</p></p>C code <ol class="dp-cpp" start="1"> <ol class="dp-cpp" start="1"> <li>-(<span class="keyword">void) applicationwillresignactive: (uiapplication*) application{</span></li> <li><span class="comment">/* add your own pending pre-set code */</span></li> <li>}</li> </ol> </ol><p><p>When your program is suspended, he will not run in the Background.</p></p><p><p></p></p><p><p><strong>Ii. Rehabilitation</strong></p></p><p><p>When the program is restored, another named Applicationdidbecomeactive delegate method is called, where you can recover your application by saving data before suspending It:</p></p>C code <ol class="dp-cpp" start="1"> <ol class="dp-cpp" start="1"> <li>-(<span class="keyword">void) applicationdidbecomeactive: (uiapplication*) application{</span></li> <li><span class="comment">/* Add your recovery code */</span></li> <li>}</li> </ol> </ol><p><p>Note: when the application starts, the Applicationdidbecomeactive method is called after the Applicationdidfinishlaunching method is called, so make sure that your code can distinguish between recovery and startup, Avoid logically occurring bugs.</p></p><p><p></p></p><p><p><strong>third, termination</strong></p></p><p><p>When the user presses the button or shuts down, the program will be Terminated. The Applicationwillterminate method is called when a program will terminate Normally. however, If the long Master button is forced to exit, the method is not Called. This method should perform the rest of the cleanup, for example, all connections will gracefully shut down and perform any other necessary work before the program Exits:</p></p>C code <ol class="dp-cpp" start="1"> <ol class="dp-cpp" start="1"> <li>-(<span class="keyword">void) applicationwillterminate: (uiapplication*) application{</span></li> <li><span class="comment">/* Add the cleanup code before exiting and other work code here */</span></li> <li>}</li> </ol> </ol> <p><p>Source: http://blog.csdn.net/iukey/article/details/7311115</p></p><p><p></p></p><p><p></p></p>Java code <ol class="dp-j" start="1"> <li><li>-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions</li></li> <li><li>{</li></li> <li><li><span class="comment">//Override point for customization after application Launch. </span></li></li> <li><li>NSLog (@<span class="string">"\ ===> program starts!"); </span></li></li> <li><li></li></li> <li><li><span class="keyword">return YES; </span></li></li> <li><li>}</li></li> <li><li></li></li> <li><li>-(<span class="keyword">void) applicationwillresignactive: (uiapplication *) application</span></li></li> <li><li>{</li></li> <li><li><span class="comment">/* </span></li></li> <li><li><span class="comment">Sent when the application are about to move from active to inactive State. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS Message) or when the US Er quits the application and it begins the transition to the background State.</span></li></li> <li><li><span class="comment">Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the Game.</span></li></li> <li><li><span class="comment">*/</span></li></li> <li><li>NSLog (@<span class="string">"\ n ===> program interim!"); </span></li></li> <li><li>}</li></li> <li><li></li></li> <li><li>-(<span class="keyword">void) applicationdidenterbackground: (uiapplication *) application</span></li></li> <li><li>{</li></li> <li><li><span class="comment">/* </span></li></li> <li><li><span class="comment">Use the method to release the shared resources, save user data, invalidate timers, and store enough application state Informa tion to the restore your application to the it is terminated later.</span></li></li> <li><li><span class="comment">If your application supports background execution, This method was called instead of Applicationwillterminate:when the use R Quits.</span></li></li> <li><li><span class="comment">*/</span></li></li> <li><li>NSLog (@<span class="string">"\ nthe ===> program goes backstage!"); </span></li></li> <li><li>}</li></li> <li><li></li></li> <li><li>-(<span class="keyword">void) applicationwillenterforeground: (uiapplication *) application</span></li></li> <li><li>{</li></li> <li><li><span class="comment">/* </span></li></li> <li><li><span class="comment">Called as part of the transition from the background to the inactive state; Here's can undo many of the changes made on entering the Background.</span></li></li> <li><li><span class="comment">*/</span></li></li> <li><li>NSLog (@<span class="string">"\ n ===> program enters the foreground!"); </span></li></li> <li><li>}</li></li> <li><li></li></li> <li><li>-(<span class="keyword">void) applicationdidbecomeactive: (uiapplication *) application</span></li></li> <li><li>{</li></li> <li><li>NSLog (@<span class="string">"\ n ===> program reactivation!"); </span></li></li> <li><li><span class="comment">/* </span></li></li> <li><li><span class="comment">Restart any tasks this were paused (or not yet started) while the application is Inactive. If the application is previously in the background, optionally refresh the user interface.</span></li></li> <li><li><span class="comment">*/</span></li></li> <li><li>}</li></li> <li><li></li></li> <li><li>-(<span class="keyword">void) applicationwillterminate: (uiapplication *) application</span></li></li> <li><li>{</li></li> <li><li>NSLog (@<span class="string">"\ n ===> Program Accidental interim!"); </span></li></li> <li><li></li></li> <li><li>Uidevice *device = [uidevice currentdevice];</li></li> <li><li><span class="comment">/* </span></li></li> <li><li><span class="comment">Called when the application are about to Terminate.</span></li></li> <li><li><span class="comment">Save Data If Appropriate.</span></li></li> <li><li><span class="comment">See also Applicationdidenterbackground:.</span></li></li> <li><li><span class="comment">*/</span></li></li> <li><li>}</li></li> </ol><p><p>First Run:</p></p><p><p>-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions</p></p><p><p>-(void) applicationdidbecomeactive: (uiapplication *) Application</p></p><p><p></p></p><p><p>First off (home):</p></p><p><p>-(void) applicationwillresignactive: (uiapplication *) Application</p></p><p><p>-(void) applicationdidenterbackground: (uiapplication *) Application</p></p><p><p></p></p><p><p>Run Again:</p></p><p><p>-(void) applicationwillenterforeground: (uiapplication *) Application</p></p><p><p>-(void) applicationdidbecomeactive: (uiapplication *) Application</p></p><p><p></p></p><p><p>Close Again:</p></p><p><p>-(void) applicationwillresignactive: (uiapplication *) Application</p></p><p><p>-(void) applicationdidenterbackground: (uiapplication *) Application</p></p><p><p>Application hangs, restores, and Terminates-ios development</p></p></span>

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.