iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I am unable to get the Crosslight Social to work correctly so I am using a Xamarin Component. The only problem is, how do I send the Json object back up to the core when its done authenticating? I tried using MobileCompnentServiceBase but it doesn't allow me to StartActivity to show the ui. Is there a way to hook this into a Binding Property?
Here is the code for Native:
using System.Net.Mime; using Android.App; using Android.Graphics; using Android.Renderscripts; using Android.Widget; using IncroudRadio.Android.Custom; using IncroudRadio.BindingProviders; using IncroudRadio.Custom; using IncroudRadio.ViewModels; using Intersoft.Crosslight; using Intersoft.Crosslight.Android; using System.Threading.Tasks; using Xamarin.Auth; using System.Json; using System.Threading.Tasks; using Android.App; using Android.Widget; using Android.OS; using System; namespace IncroudRadio.Android.Activities { [Activity(Theme = "@style/Theme.Home")] [ImportBinding(typeof(LoginBindingProvider))] [RegisterNavigation(IsRootView = true)] public class HomeActivity : Activity<HomeViewModel> { #region Constructors public HomeActivity() : base(Resource.Layout.home_activity) { } protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); //SetContentView(Resource.Layout.home_activity); var facebook = FindViewById<Button>(Resource.Id.fb); facebook.Click += delegate { LoginToFacebook(false); }; } public void LoginToFacebook(bool allowCancel) { var auth = new OAuth2Authenticator( clientId: "Client ID", scope: "email", authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"), redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html")); auth.AllowCancel = allowCancel; // If authorization succeeds or is canceled, .Completed will be fired. auth.Completed += (s, ee) => { if (!ee.IsAuthenticated) { var builder = new AlertDialog.Builder(this); builder.SetMessage("Not Authenticated"); builder.SetPositiveButton("Ok", (o, e) => { }); builder.Create().Show(); return; } // Now that we're logged in, make a OAuth2 request to get the user's info. var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, ee.Account); request.GetResponseAsync().ContinueWith(t => { var builder = new AlertDialog.Builder(this); if (t.IsFaulted) { builder.SetTitle("Error"); builder.SetMessage(t.Exception.Flatten().InnerException.ToString()); } else if (t.IsCanceled) builder.SetTitle("Task Canceled"); else { var obj = JsonValue.Parse(t.Result.GetResponseText()); builder.SetTitle("Logged in"); builder.SetMessage("Name: " + obj["name"] + " " + obj["email"]); } builder.SetPositiveButton("Ok", (o, e) => { }); builder.Create().Show(); }, UIScheduler); }; var intent = auth.GetUI(this); StartActivity(intent); IncroudRadioFacebook test = new IncroudRadioFacebookAndroid(); } private static readonly TaskScheduler UIScheduler = TaskScheduler.FromCurrentSynchronizationContext(); #endregion } }
Hello,Thank you for the question regarding Crosslight.I have created a Crosslight project that using custom service that perhaps can be the best approach with your current scenario. The custom service will return the string to the ViewModel through callback.First, I created a simple Crosslight sample by using Blank project template.Next, I added an interface called ‘ICustomService’ which inherits ‘IMobileComponentService’. The snippet code below shows how the interface is declared in ‘ICustomService.cs’ file in the Core project.
using Intersoft.Crosslight.Mobile; namespace CustomService.Core.Custom { public interface ICustomService : IMobileComponentService { void DoSomething(Action<string> callback); } }
In the SimpleViewModel class, ShowToast function is modified by resolving CustomService via IoC (injection of Container) technique. If customService is not null, invokes 'DoSomething()' method.
private void ShowToast(object parameter) { //this.ToastPresenter.Show("You entered: " + this.NewText); //this.GreetingText = this.NewText; ICustomService customService = ServiceProvider.GetService<ICustomService>(); //resolve CustomService via IoC (injection of Container) if (customService != null) { customService.SetOwner(this); //needed for Android platform only customService.DoSomething((callback) => { //do something with the callback System.Diagnostics.Debug.WriteLine(callback); }); } }
Next, we need to register the custom service in the AppInitializer class, specifically in the InitializeServices method.
public void InitializeServices(IApplicationHost appHost) { ServiceProvider.AddService<ICustomService, CustomiOSService>(); }
Please note that we need to repeat this step for each platform (Android, iOS, Windows Phone, and Windows StoreApp).Last, implement DoSomething method for each platform. In the sample, what DoSomething doing is very easy, it shows "Custom Service" alert and send the string value back to ViewModel.
using CustomService.Core.Custom; using Intersoft.Crosslight.iOS; using MonoTouch.UIKit; namespace CustomService.iOS.Custom { public class CustomiOSService : IOSMobileComponentServiceBase, ICustomService { public void DoSomething() { UIAlertView alert = new UIAlertView("Custom service", "Custom Service", null, "OK", null); alert.Show(); // to send string value to the ViewModel callback("test"); } } }
The sample can be downloaded in http://git.intersoftpt.com/projects/CROS-SUPP/repos/custom-service/browse. Please let us know whether this help or not.Regards,Hans K.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname