2

I want to logout from application using settings bundle.

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

//enable_logout key for logout switch identifire in setting budle plist.
        let userLogout =  UserDefaults.standard.bool(forKey: "enabled_logout")
        print(userLogout)

            let userLogin =  UserDefaults.standard.bool(forKey: "isUserLogin")
            if userLogin {

                let homeController = HomeController()
                let homeNav = UINavigationController.init(rootViewController: homeController)


                let aboutController = AboutController()
                let aboutNav = UINavigationController.init(rootViewController: aboutController)

                let userBaseController = UserBaseInfoController()
                let userBaseNav = UINavigationController.init(rootViewController: userBaseController)

                tabbarController.viewControllers =[homeNav,userBaseNav,aboutNav]

                self.window?.rootViewController = tabbarController

            }
            else {

                let login = LoginController()
                self.window?.rootViewController = login


            }



        return true
    }

I'm added this code in appDelegate, I want to when the user enables logout switch in setting and then return to application show login view, but when enables switch and back to app appDelegate not call and my key not change.

There is my setting view : enter image description here

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
ava
  • 1,148
  • 5
  • 15
  • 44

1 Answers1

0

I am solve this problem, instead check enable_logout key in didFinishLaunchingWithOptions method, I checked in applicationWillEnterForeground methods.

Here is my code:

func applicationWillEnterForeground(_ application: UIApplication) {

        let userLogout =  UserDefaults.standard.bool(forKey: "enable_logout")
        print(userLogout)


        if !userLogout {

            let homeController = HomeController()
            let homeNav = UINavigationController.init(rootViewController: homeController)


            let aboutController = AboutController()
            let aboutNav = UINavigationController.init(rootViewController: aboutController)

            let userBaseController = UserBaseInfoController()
            let userBaseNav = UINavigationController.init(rootViewController: userBaseController)

            tabbarController.viewControllers = [homeNav,userBaseNav,aboutNav]

            self.window?.rootViewController = tabbarController

        }
        else {

            let login = LoginController()
            self.window?.rootViewController = login

        }

    }
ava
  • 1,148
  • 5
  • 15
  • 44
  • hi can you send message on telegram to me I'm iranian and need your help for signalR ..thanks in advance ... this is my id on telegram : mohammad_Z744 –  Apr 24 '17 at 18:57
  • @M_STRM74 hi thats my email address you can ask question here : qazaleh.afrough@gmail.com – ava Apr 26 '17 at 10:14