追风赶月莫停留,平芜尽处是春山。这篇文章主要讲述App开发 对生命周期的处理相关的知识,希望能为你提供帮助。
//获取到当前所在的视图
- (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 --当应用程序退出后台进行的操作
- (void)applicationDidEnterBackground:(UIApplication *)application {
//进入后台执行的操作
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 --应用程序进入后台再进入前台进行的操作
- (void)applicationWillEnterForeground:(UIApplication *)application {
//进入前台执行的操作---原生页面
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"root"] isEqualToString:@"0"]) {
//进入原生页面的不作处理
[self goBackForViewController];
}
//如果停留在H5页面,重新加载,防止session过期问题
else{
[self showViewControllers];
}
}
【App开发 对生命周期的处理】Documents:在ios应用开发中使用应用周期进行相关的操作,可以很好处理应用生命周期之间的交互问题
推荐阅读
- Win 8系统应用商店中无法登录微软账户怎样办
- App安全
- android开发学习 ------- EventBus的学习理解
- Linux自学笔记——tcp wrapper
- What would be the closest equivalent in Java to a Micro ORM such as Dapper, PetaPoco, Massive or Cod
- Android JNI编程—JNI基础
- 安卓虚拟机与Hyper-V冲突
- Visual simultaneous localization and mapping: a survey 论文解析(全)
- (转)html5唤起app的方法