private void CreateAndPresentLoginView()
 {
     if (loginViewController == null)
     {
         loginViewController = new SCLoginViewController();
         navController.TopViewController.PresentModalViewController(loginViewController, false);
     }
 }
        public void OnSessionStateChanged(FBSession session, FBSessionState state, NSError error)
        {
            // FBSample logic
            // Any time the session is closed, we want to display the login controller (the user
            // cannot use the application unless they are logged in to Facebook). When the session
            // is opened successfully, hide the login controller and show the main UI.
            switch (state)
            {
            case FBSessionState.Open:
                this.mainViewController.StartLocationManager();
                if (loginViewController != null)
                {
                    navController.TopViewController.DismissViewController(true, null);
                    loginViewController = null;
                }

                // FBSample logic
                // Pre-fetch and cache the friends for the friend picker as soon as possible to improve
                // responsiveness when the user tags their friends.
                FBCacheDescriptor cacheDescriptor = FBFriendPickerViewController.CacheDescriptor();
                cacheDescriptor.PrefetchAndCacheForSession(session);
                break;

            case FBSessionState.Closed:
                // FBSample logic
                // Once the user has logged out, we want them to be looking at the root view.
                // and to clear the user Token
                if (navController.TopViewController.ModalViewController != null)
                {
                    navController.TopViewController.DismissViewController(false, null);
                }

                navController.PopToRootViewController(false);
                FBSession.ActiveSession.CloseAndClearTokenInformation();
                ShowLoginView();
                break;

            case FBSessionState.ClosedLoginFailed:
                // if the token goes invalid we want to switch right back to
                // the login view, however we do it with a slight delay in order to
                // account for a race between this and the login view dissappearing
                // a moment before
                this.ShowLoginView();
                break;

            default:
                break;
            }

            NSNotificationCenter.DefaultCenter.PostNotificationName(SCSessionStateChangedNotification, session);

            if (error != null)
            {
                UIAlertView alertView = new UIAlertView("Error: " + ((FBErrorCode)error.Code).ToString(), error.LocalizedDescription, null, "Ok", null);
                alertView.Show();
            }
        }
        public void OnSessionStateChanged(FBSession session, FBSessionState state, NSError error)
        {
            // FBSample logic
            // Any time the session is closed, we want to display the login controller (the user
            // cannot use the application unless they are logged in to Facebook). When the session
            // is opened successfully, hide the login controller and show the main UI.
            switch (state)
            {

            case FBSessionState.Open:
                this.mainViewController.StartLocationManager();
                if (loginViewController != null)
                {
                    navController.TopViewController.DismissViewController(true, null);
                    loginViewController = null;
                }

                // FBSample logic
                // Pre-fetch and cache the friends for the friend picker as soon as possible to improve
                // responsiveness when the user tags their friends.
                FBCacheDescriptor cacheDescriptor = FBFriendPickerViewController.CacheDescriptor();
                cacheDescriptor.PrefetchAndCacheForSession(session);
                break;

            case FBSessionState.Closed:
                // FBSample logic
                // Once the user has logged out, we want them to be looking at the root view.
                // and to clear the user Token
                if (navController.TopViewController.ModalViewController != null)
                    navController.TopViewController.DismissViewController(false, null);

                navController.PopToRootViewController(false);
                FBSession.ActiveSession.CloseAndClearTokenInformation();
                ShowLoginView();
                break;

            case FBSessionState.ClosedLoginFailed:
                // if the token goes invalid we want to switch right back to
                // the login view, however we do it with a slight delay in order to
                // account for a race between this and the login view dissappearing
                // a moment before
                this.ShowLoginView();
                break;

            default:
                break;
            }

            NSNotificationCenter.DefaultCenter.PostNotificationName(SCSessionStateChangedNotification, session);

            if (error != null)
            {
                UIAlertView alertView = new UIAlertView("Error: " + ((FBErrorCode)error.Code).ToString(), error.LocalizedDescription, null, "Ok", null);
                alertView.Show();
            }
        }
 private void CreateAndPresentLoginView()
 {
     if (loginViewController == null)
     {
         loginViewController = new SCLoginViewController();
         navController.TopViewController.PresentModalViewController(loginViewController, false);
     }
 }