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 override void ViewDidUnload() { base.ViewDidUnload(); // Clear any references to subviews of the main view in order to // allow the Garbage Collector to collect them sooner. // // e.g. myOutlet.Dispose (); myOutlet = null; NSNotificationCenter.DefaultCenter.RemoveObserver(this); friendPickerController = null; placePickerController = null; imagePicker = null; ReleaseDesignerOutlets(); }
// Using Native Friend Picker Controller void FriendPicker() { var friendController = new FBFriendPickerViewController() { Title = "Pick some friends" }; friendController.LoadData(); friendController.PresentModallyFromViewController(this, true, (sender, donePressed) => { if (!donePressed) { InvokeOnMainThread(() => new UIAlertView("Error", "User canceled.", null, "Ok", null).Show()); } else { var ctrl = sender as FBFriendPickerViewController; foreach (var friend in ctrl.Selection) { Console.WriteLine(friend.Name); } InvokeOnMainThread(() => new UIAlertView("Success", "You Picked " + ctrl.Selection.Count() + " friend(s)", null, "Ok", null).Show()); } }); }