Lifecycle processing for app development

Source: Internet
Author: User

Get to the current view

-(Uiviewcontroller *) PRESENTINGVC: (uiapplication *) application{

UIWindow * window = Application.keywindow;

if (window.windowlevel! = uiwindowlevelnormal) {

Nsarray *windows = [[UIApplication sharedapplication] windows];

For (UIWindow * Tmpwin in Windows) {

if (Tmpwin.windowlevel = = Uiwindowlevelnormal) {

window = Tmpwin;

Break

}

}

}

Uiviewcontroller *result = Window.rootviewcontroller;

while (Result.presentedviewcontroller) {

result = Result.presentedviewcontroller;

}

if ([Result Iskindofclass:[mytabbarviewcontroller class]]) {

result = [(Mytabbarviewcontroller *) result Selectedviewcontroller];

}

if ([Result Iskindofclass:[uinavigationcontroller class]]) {

result = [(Uinavigationcontroller *) result Topviewcontroller];

}

return result;

}

#p-action when the application exits the background

-(void) Applicationdidenterbackground: (uiapplication *) Application {

Actions to go into the background

Uiviewcontroller *VIEWC = [self presentingvc:application];

NSLog (@ "viewc==%@", [VIEWC class]);

if ([Viewc class]== [Loginviewcontroller class]) {

[[Nsuserdefaults Standarduserdefaults] setobject:@ "1" forkey:@ "root"];

}else{

[[Nsuserdefaults Standarduserdefaults] setobject:@ "0" forkey:@ "root"];

[Self gobackforviewcontroller];

}

}

#p-Operations that the application enters the background and then enters the foreground

-(void) Applicationwillenterforeground: (uiapplication *) Application {

---Native page for actions performed in the foreground

if ([[[[[Nsuserdefaults Standarduserdefaults] objectforkey:@ "root"] isequaltostring:@ "0"]) {

Do not process into the native page

[Self gobackforviewcontroller];

}

If you stay on the H5 page, reload to prevent the session from expiring.

else{

[Self showviewcontrollers];

}

}

Documents: Use the application lifecycle in iOS app development for related operations that can handle the interaction issues between application lifecycles well

Lifecycle processing for app development

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.