Example #1
0
        public void FBLoginButtonSetting()
        {
            UIApplication.SharedApplication.BeginInvokeOnMainThread(() =>
            {
                #region loginButton Setting
                var facebookLoginButtonText = new NSAttributedString("以FB登入並繼續");

                LoginBtn.SetAttributedTitle(facebookLoginButtonText, UIControlState.Normal);
                LoginBtn.LoginBehavior   = LoginBehavior.Native;
                LoginBtn.ReadPermissions = Common.Variables.FBPermissions.ToArray();
                if (token != null)
                {
                    LoginBtn.SetAttributedTitle(new NSAttributedString("登出"), UIControlState.Normal);
                    ProfileName.Text = "Hi! " + currentProfile.Name + " 大美女";
                }

                #endregion

                // The user image profile is set automatically once is logged in
                pictureView = new ProfilePictureView(new CGRect(50, 50, 220, 220));

                // Create the label that will hold user's facebook name
                nameLabel = new UILabel(new RectangleF(20, 319, 280, 21))
                {
                    TextAlignment   = UITextAlignment.Center,
                    BackgroundColor = UIColor.Clear
                };
                loadingView.Hide();
            });


            // Handle actions once the user is logged in
            LoginBtn.Completed += (sender, e) =>
            {
                var SplitVC  = this.Storyboard.InstantiateViewController("SplitViewController");
                var listView = SplitVC.View;
                if (e.Error != null)
                {
                    // Handle if there was an error
                }

                if (e.Result.IsCancelled)
                {
                    // Handle if the user cancelled the login request
                }
                View.AddSubview(loadingView);
                // Handle your successful login
                token = AccessToken.CurrentAccessToken;
                if (token != null)
                {
                    LoginBtn.SetAttributedTitle(new NSAttributedString("登出"), UIControlState.Normal);
                    SplitVC.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
                    this.PresentViewController(SplitVC, true, null);
                }
            };

            // Handle actions once the user is logged out
            LoginBtn.LoggedOut += (sender, e) =>
            {
                // Handle your logout
                token = AccessToken.CurrentAccessToken;
                if (token == null)
                {
                    LoginBtn.SetAttributedTitle(new NSAttributedString("以FB進行登入"), UIControlState.Normal);
                }
            };
        }