简体   繁体   English

使用MMDrawer在iOS中进行状态保存和恢复问题

[英]State Preservation and Restoration issue in iOS using MMDrawer

I have integrated the MMDrawerController Library in an iOS application and now I have a requirement to Restore application state even though application is killed in background(Only when application is enter from foreground to background), it is working fine with normal navigation application but when I change Navigation using " setCenterViewController " option in my application, restoration is not working as expected and I have followed all instruction provided in this link: " https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html " 我已经在iOS应用程序中集成了MMDrawerController库,现在我需要恢复应用程序状态,即使应用程序在后台被杀死(仅当应用程序从前台输入到后台时),它在正常的导航应用程序中工作正常但是当我在我的应用程序中使用“ setCenterViewController ”选项更改导航,恢复无法按预期工作,并且我已按照此链接中提供的所有说明操作:“ https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html

I have used setCenterViewController option(Recommended from MMDrawer) to navigates to particular screen and then deleted app in background , When we reopened it is launching with default initial screen but we are expecting it should reopen with Screen it has before Entering to Background. 我已经使用了setCenterViewController选项(推荐来自MMDrawer)导航到特定的屏幕,然后在后台删除应用程序,当我们重新打开它时会启动默认的初始屏幕,但我们期望它应该在进入后台之前重新打开屏幕。

and here is the code snippet: 这是代码片段:

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.homeController.navigationController.navigationBarHidden = YES;
HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *_navg = [[UINavigationController alloc]initWithRootViewController:homeVC];
_navg.restorationIdentifier = @"homeNavigationController";
homeVC.title = [self.dataSource objectAtIndex:indexPath.row]; homeVC.restorationIdentifier = @"HomeViewController";
[appDelegate.drawerController setCenterViewController:_navg withCloseAnimation:YES completion:nil];
self.currentViewController = _navg;
self.currentViewController.restorationIdentifier = @"homeNavigationController"; 

Help me to resolve this issue. 帮我解决这个问题。

You can easily do state preservation by storing states in NSUUserDefault Do the following steps: 1.When you launch the app first time. 您可以通过在NSUUserDefault中存储状态轻松地进行状态保存。执行以下步骤:1。首次启动应用程序时。

  {
      UserDefaults.standard.set("0", forKey: "state")
     UserDefaults.standard.synchronize()
   }

2.When you kill the app then store the state 2.当你杀死应用程序然后存储状态

   {    
            UserDefaults.standard.set("1", forKey: "state")
             UserDefaults.standard.synchronize()
        }

3. When you relaunch the app get the state ,setup the drawer and move to particular controller using it's navigation controller.



 if let state = UserDefaults.standard.object(forKey: "state") as? String{
         switch state{
                case "0":
                        //Do setup for MMDrawer for center ,left and right view
                        break
                case "1":
                        //Do setup for MMDrawer for center ,left and right view

                break
                 default:
                        break
                    }
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM