//------------------------------------------------------------------------------ public override void ViewDidLoad() { base.ViewDidLoad(); LoginManager login = new LoginManager(); login.LoginBehavior = LoginBehavior.Web; login.LogOut(); login.LogInWithReadPermissions(readPermissions.ToArray(), null, delegate(LoginManagerLoginResult result, NSError error) { if (error != null) { UpdateCredentials(string.Empty); } else if (result.IsCancelled) { UpdateCredentials(string.Empty); ((AppDelegate)UIApplication.SharedApplication.Delegate).Continue(new SettingsViewController { AddLoginButton = true, AddSyncInProgressLabel = false, EnableSettingsReload = false, AddSyncDatasetButton = false, }); } else { var accessToken = result.Token; UpdateCredentials(accessToken.TokenString); var appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate; appDelegate.SynchronizeSettings(); appDelegate.Continue(new SettingsViewController { AddLoginButton = false, AddLogoutButton = true, AddSyncInProgressLabel = true, EnableSettingsReload = true, AddSyncDatasetButton = true, }); // plugins are persistant and next call return the same object var plugin = CognitoSyncSettings.GetPlugin <ICognitoSyncSettingsPlugin>(); plugin.SynchronizeDataset(); } }); }
//------------------------------------------------------------------------------ public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { Profile.EnableUpdatesOnAccessTokenChange(true); Settings.AppId = Constants.FacebookAppId; Settings.DisplayName = Constants.FacebookAppName; CognitoSyncSettings.LoadSettings(); // plugins are persistant per instance (static settings processed by separate, internal instance) // and next call will return the same object var plugin = CognitoSyncSettings.GetPlugin <ICognitoSyncSettingsPlugin>(); plugin.OnSyncSuccess += (sender, e) => { var el = m_ViewController as ICognitoSyncEventsListerner; InvokeOnMainThread(() => { if (el != null) { el.OnSyncSuccess(sender, e); } }); }; plugin.OnSyncFailure += (sender, e) => { var el = m_ViewController as ICognitoSyncEventsListerner; InvokeOnMainThread(() => { if (el != null) { el.OnSyncFailure(sender, e); } }); }; plugin.OnDatasetDeleted = delegate(Dataset ds) { // Do clean up if necessary // returning true informs the corresponding dataset can be purged in the local storage and return false retains the local dataset return(true); }; plugin.OnDatasetMerged = delegate(Dataset dataset, List <string> datasetNames) { // returning true allows the Synchronize to continue and false stops it return(true); }; plugin.OnSyncConflict = delegate(Dataset dataset, List <SyncConflict> conflicts) { var resolvedRecords = new List <Amazon.CognitoSync.SyncManager.Record>(); foreach (SyncConflict conflictRecord in conflicts) { // SyncManager provides the following default conflict resolution methods: // ResolveWithRemoteRecord - overwrites the local with remote records // ResolveWithLocalRecord - overwrites the remote with local records // ResolveWithValue - to implement your own logic resolvedRecords.Add(conflictRecord.ResolveWithRemoteRecord()); } // resolves the conflicts in local storage dataset.Resolve(resolvedRecords); // on return true the synchronize operation continues where it left, // returning false cancels the synchronize operation return(true); }; Window = new UIWindow(UIScreen.MainScreen.Bounds); Continue(new SettingsViewController() { AddLoginButton = true }); Window.MakeKeyAndVisible(); // This method verifies if you have been logged into the app before, and keep you logged in after you reopen or kill your app. return(ApplicationDelegate.SharedInstance.FinishedLaunching(application, launchOptions)); }