使用Rivets与Xamarins.Forms进行深层链接

时间:2016-05-10 20:29:57

标签: xamarin deep-linking rivets

因此,当我网站中的用户请求新密码时,我会向他的电子邮件地址发送一个链接,该链接指向我的网站headers。我的移动应用程序应该会打开。

我在我的Android Xamarin项目中通过NuGet安装了Rivets包。

这是我的MainActivity.cs代码:

using System;
using Android.App;
using Android.Content.PM;
using Android.OS;
using TinyIoC;
using XLabs.Forms;
using XLabs.Ioc;
using XLabs.Platform.Device;
using Android.Content;
using Android.Preferences;
using XLabs.Platform.Services;
using XLabs.Platform.Services.Media;

namespace HalliganTL.Droid
{
    [Activity(Label = "Halligan", 
        Icon = "@drawable/icon", 
        MainLauncher = true, 
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(new[] { Android.Content.Intent.ActionView },
        DataScheme = "halligan",
        DataHost = "resetpassword",
        Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable })]
    public class MainActivity : XFormsApplicationDroid, IDeviceStorage
    {
        #region IDeviceStorage implementation
        public string LoadString(string key, string def = null)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            return prefs.GetString(key, def);
        }

        public void SaveString(string key, string value)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            ISharedPreferencesEditor editor = prefs.Edit();
            editor.PutString(key, value);
            editor.Apply();
        }
        #endregion

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);
            if (!Resolver.IsSet) SetIoc();

            //We're gonna check if we opened the app from a web link
            var resetPasswordToken = string.Empty;
            Rivets.AppLinkUrl alUrl = null;

            // Parse our AppLinkUrl from the Intent Data Uri
            if (Intent.Data != null)
            {
                alUrl = new Rivets.AppLinkUrl(Intent.Data.ToString());
            }

            if (alUrl != null && alUrl.TargetQueryParameters.ContainsKey("token"))
                resetPasswordToken = alUrl.TargetQueryParameters["token"];

            if (string.IsNullOrEmpty(resetPasswordToken))
            {
                LoadApplication(new App());
            } 
            else
            {
                LoadApplication(new App(resetPasswordToken));
            }
        }

        private void SetIoc()
        {
            var container = TinyIoCContainer.Current;
            container.Register<IDeviceStorage>(this);
            container.Register<IDevice>(AndroidDevice.CurrentDevice);
            container.Register<IMediaPicker, MediaPicker>();
            container.Register<ISecureStorage>(new KeyVaultStorage(container.Resolve<IDevice>().Id.ToCharArray()));
            Resolver.SetResolver(new XLabs.Ioc.TinyIOC.TinyResolver(container));
        }

    }
}

没有任何事情发生。

BTW我正在使用Rivets 1.0.2版本,因为较新的版本抛出了“程序集引用错误”,说我的项目有“MonoAndroid,Version = v6.0”

任何提示都会有用,

0 个答案:

没有答案