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