     func applicationWillTerminate(application: UIApplication) {
         // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
         print("applicationWillTerminate") //ignore
-        print(application)
         
         Answers.logCustomEventWithName("Application Terminated",
                                        customAttributes: [:])

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
        print("applicationWillEnterForeground")
        print(application)
        
        Answers.logCustomEventWithName("Application Will Enter Foreground",
                                       customAttributes: [:])

        //
        // if denied access users can change permissions later
        // display root controller otherwise
        guard let firstTime = NSUserDefaults.standardUserDefaults().valueForKey("firstTime") else {
            // IMPORTANT: load new access token on appdelegate load, otherwise the old token will be requested to the server
            userAccessToken = NSUserDefaults.standardUserDefaults().valueForKey("userAccessToken")
            if userAccessToken != nil {
                let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("RootViewController")
                self.window!.rootViewController = viewController
            } else {
                let sb = UIStoryboard(name: "Main", bundle: nil)
                let rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("RootViewController")
                let vc = sb.instantiateViewControllerWithIdentifier("LoginViewController")
                vc.modalTransitionStyle = .CrossDissolve
                self.window!.rootViewController = rootViewController
                rootViewController.presentViewController(vc, animated: false, completion: { _ in
                    print("showing login")
                })
            }
            return
        }

        if String(firstTime) == "" {
            
            Answers.logCustomEventWithName("First Time Launch",
                                           customAttributes: [:])
            
            NSUserDefaults.standardUserDefaults().setValue("launched", forKey: "firstTime")
            NSUserDefaults.standardUserDefaults().synchronize()
            
            let sb = UIStoryboard(name: "Auth", bundle: nil)
            let rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("RootViewController")
            let vc = sb.instantiateViewControllerWithIdentifier("authViewController")
            vc.modalTransitionStyle = .CrossDissolve
            self.window!.rootViewController = rootViewController
            rootViewController.presentViewController(vc, animated: false, completion: { _ in
                print("showing auth")
            })
            
            // Show dialog with callbacks
            pscope.show({ finished, results in
                // Enable push notifications
