﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - Native Question</title><link>http://www.intersoftsolutions.com/Community/Crosslight/Native-Question/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>Native Question</title><link>http://www.intersoftsolutions.com/Community/Crosslight/Native-Question/</link><pubDate>Thu, 02 Oct 2014 04:20:06 GMT</pubDate><dc:creator>Hans</dc:creator><description>&lt;p&gt;Hello,&lt;br&gt;&lt;br&gt;Thank you for the question regarding Crosslight.&lt;br&gt;&lt;br&gt;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.&lt;br&gt;&lt;br&gt;First, I created a simple Crosslight sample by using Blank project template.&lt;br&gt;&lt;br&gt;Next, I added an interface called ‘&lt;span style="font-weight: bold;"&gt;ICustomService&lt;/span&gt;’ which inherits ‘&lt;span style="font-weight: bold;"&gt;IMobileComponentService&lt;/span&gt;’. The snippet code below shows how the interface is declared in ‘&lt;span style="font-weight: bold;"&gt;ICustomService.cs&lt;/span&gt;’ file in the Core project.&lt;br&gt;&lt;/p&gt;&lt;pre&gt;using Intersoft.Crosslight.Mobile;
namespace CustomService.Core.Custom
{
    public interface ICustomService : IMobileComponentService
    {
        void DoSomething(Action&amp;lt;string&amp;gt; callback);
    }
}&lt;/pre&gt;&lt;p&gt;In the &lt;span style="font-weight: bold;"&gt;SimpleViewModel&lt;/span&gt; class, &lt;span style="font-weight: bold;"&gt;ShowToast&lt;/span&gt; function is modified by resolving CustomService via IoC (injection of Container) technique. If customService is not null, invokes '&lt;span style="font-weight: bold;"&gt;DoSomething()&lt;/span&gt;' method.&lt;br&gt;&lt;/p&gt;&lt;pre&gt;private void ShowToast(object parameter)
{
    //this.ToastPresenter.Show("You entered: " + this.NewText);
    //this.GreetingText = this.NewText;

    ICustomService customService = ServiceProvider.GetService&amp;lt;ICustomService&amp;gt;(); //resolve CustomService via IoC (injection of Container)
    if (customService != null)
    {
        customService.SetOwner(this); //needed for Android platform only
        customService.DoSomething((callback) =&amp;gt; { 
            //do something with the callback
            System.Diagnostics.Debug.WriteLine(callback);
        });
    }
}&lt;/pre&gt;&lt;p&gt;Next, we need to register the custom service in the &lt;span style="font-weight: bold;"&gt;AppInitializer &lt;/span&gt;class, specifically in the InitializeServices method.&lt;br&gt;&lt;/p&gt;&lt;pre&gt;public void InitializeServices(IApplicationHost appHost)
{
    ServiceProvider.AddService&amp;lt;ICustomService, CustomiOSService&amp;gt;();
}&lt;/pre&gt;&lt;p&gt;Please note that we need to repeat this step for &lt;span style="font-weight: bold;"&gt;each platform&lt;/span&gt; (Android, iOS, Windows Phone, and Windows StoreApp).&lt;br&gt;&lt;br&gt;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.&lt;br&gt;&lt;/p&gt;&lt;pre&gt;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");
        }
    }
}&lt;/pre&gt;&lt;p&gt;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.&lt;br&gt;&lt;br&gt;Regards,&lt;br&gt;Hans K.&lt;br&gt;&lt;/p&gt;</description></item><item><title>Native Question</title><link>http://www.intersoftsolutions.com/Community/Crosslight/Native-Question/</link><pubDate>Tue, 30 Sep 2014 05:32:34 GMT</pubDate><dc:creator>devincroud</dc:creator><description>&lt;p&gt;I am unable to get the Crosslight Social to work correctly so I am using a Xamarin Component. &amp;nbsp;The only problem is, how do I send the Json object back up to the core when its done authenticating? &amp;nbsp;I tried using MobileCompnentServiceBase but it doesn't allow me to StartActivity to show the ui. &amp;nbsp;Is there a way to hook this into a Binding Property?&lt;/p&gt;&lt;p&gt;Here is the code for Native:&lt;/p&gt;&lt;pre&gt;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&amp;lt;HomeViewModel&amp;gt;
    {
        #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&amp;lt;Button&amp;gt;(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) =&amp;gt;
            {
                if (!ee.IsAuthenticated)
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetMessage("Not Authenticated");
                    builder.SetPositiveButton("Ok", (o, e) =&amp;gt; { });
                    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 =&amp;gt;
                {
                    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) =&amp;gt; { });
                    builder.Create().Show();
                }, UIScheduler);

            };

            var intent = auth.GetUI(this);
            StartActivity(intent);
            IncroudRadioFacebook test = new IncroudRadioFacebookAndroid();
            
            
        }
        private static readonly TaskScheduler UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
        #endregion
    }
}&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>