public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            RemoveBackBarButtonTitle();

            Profile.Notifications.ObserveDidChange((sender, e) =>
            {
                if (e.NewProfile == null)
                {
                    return;
                }

                pictureView.ProfileId  = e.NewProfile.UserID;
                FacebookNameLabel.Text = e.NewProfile.Name;

                var outlet    = new Outlet();
                outlet.Name   = e.NewProfile.Name;
                outlet.Handle = e.NewProfile.UserID;
                outlet.Locked = true;
                outlet.Type   = Outlet.outlet_type_facebook;
                RealmServices.SaveOutlet(outlet);

                loginView.RemoveFromSuperview();
            });

            // Set the Read and Publish permissions you want to get
            loginView = new LoginButton(FacebookButtonSuperview.Bounds)
            {
                LoginBehavior   = LoginBehavior.Browser,
                ReadPermissions = readPermissions.ToArray()
            };

            // Handle actions once the user is logged in
            loginView.Completed += async(sender, e) =>
            {
                loginView.RemoveFromSuperview();

                await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(2));

                NavigationController.PopViewController(true);
            };
            FacebookButtonSuperview.AddSubview(loginView);

            pictureView = new ProfilePictureView(FacebookProfilePictureSuperview.Bounds);
            FacebookProfilePictureSuperview.AddSubview(pictureView);
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();


            Profile.Notifications.ObserveDidChange((sender, e) =>
            {
                if (e.NewProfile == null)
                {
                    return;
                }

                Shared.FacebookFirstName = e.NewProfile.FirstName;
                Shared.FacebookLastName  = e.NewProfile.LastName;
                Shared.FacebookUserId    = e.NewProfile.UserID;
                Shared.FacebookFullName  = e.NewProfile.Name;

                Shared.SetUserData(Shared.FacebookUserId, Shared.FacebookFirstName, Shared.FacebookLastName);
            });
            // Set the Read and Publish permissions you want to get
            loginView = new LoginButton(FacebookButtonSuperview.Bounds)
            {
                LoginBehavior   = LoginBehavior.Native,
                ReadPermissions = Shared.FacebookPermissions.ToArray()
            };

            // Handle actions once the user is logged in
            loginView.Completed += async(sender, e) =>
            {
                if (e == null)
                {
                    return;
                }
                if (e.Result != null && e.Result.IsCancelled)
                {
                    return;
                }

                if (e.Error != null)
                {
                    AppCenterManager.Report(e.Error.LocalizedDescription);
                    AppCenterManager.Report("2");
                    ShowAlert("Oops!", e.Error.LocalizedDescription);
                    return;
                }

                if (e.Result.Token == null)
                {
                    return;
                }
                string tokenString = e.Result.Token.TokenString;

                if (String.IsNullOrEmpty(tokenString))
                {
                    ShowAlert("3", "Token Empty");
                    AppCenterManager.Report("3");
                    return;
                }

                ShowHud("Loading");

                bool sucessful = await Shared.CreateUser(tokenString);

                if (!sucessful)
                {
                    HideHud();
                    new LoginManager().LogOut();
                    RealmUserServices.Logout();
                    AppCenterManager.Report("4");
                    return;
                }


                HideHud();
                NextPage();
            };

            // Handle actions once the user is logged out
            loginView.LoggedOut += (s, ev) =>
            {
                if (LogoutCancellationToken == null)
                {
                    LogoutCancellationToken = new CancellationTokenSource();
                    SettingsShared.Logout(LogoutCancellationToken.Token);
                }
            };
            FacebookButtonSuperview.AddSubview(loginView);
        }