10

我已将MMDrawerController库集成到 iOS 应用程序中,现在我需要恢复应用程序状态,即使应用程序在后台被杀死(仅当应用程序从前台进入后台时),它与普通导航应用程序一起工作但当我在我的应用程序中使用“ setCenterViewController ”选项更改导航,恢复未按预期工作,我已遵循此链接中提供的所有说明:“ https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html "

我使用setCenterViewController选项(从 MMDrawer 推荐)导航到特定屏幕,然后在后台删除应用程序,当我们重新打开它时,它会以默认初始屏幕启动,但我们希望它应该在进入后台之前使用它的屏幕重新打开。

这是代码片段:

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"; 

帮我解决这个问题。

4

1 回答 1

0

您可以通过将状态存储在 NSUUserDefault 中轻松地进行状态保存执行以下步骤: 1.当您第一次启动应用程序时。

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

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
                    }
                }
于 2018-02-12T10:51:51.047 回答