【问题标题】:Xamarin.forms cannot convert from object to system.type with Xamarin.Auth and specific android platformXamarin.forms 无法使用 Xamarin.Auth 和特定的 android 平台从对象转换为 system.type
【发布时间】:2017-08-15 20:45:21
【问题描述】:

我正在 Xamarin.Forms 应用中实现身份验证。我在看这个样本“TodoAWSAuth - Configuring Google as an OAuth identity provider”。在我为 android 实现的 OAuthLoginPresenter 中,我有这个代码: 使用 Xamarin.Auth;

 namespace InstagramApp.Droid
 {
   public class OAuthLoginPresenter
   {
      public void Login(Authenticator authenticator)
      {
        Xamarin.Forms.Forms.Context.StartActivity(authenticator.GetUI(Xamarin.Forms.Forms.Context));
      }
   }
 }

我的:

Xamarin.Forms.Forms.Context.StartActivity(authenticator.GetUI(Xamarin.Forms.Forms.Context));

返回我:

参数 1:无法从 'object' 转换为 'System.Type'

与链接中的示例相同。可能是什么问题?

同样在 Xamarin 文档中,代码是相同的: Xamarin.Auth documentation

谢谢大家

【问题讨论】:

  • 你有包含 android 项目中特定类型的程序集的引用吗?

标签: c# android authentication login xamarin.forms


【解决方案1】:

Xamarin.Auth 1.4.x 支持自定义选项卡和 SafariViewController,但没有 Xamarin.Forms 支持大多数用户想要的。 Xamarin.Forms 支持在即将发布的 1.5.0-alpha 中。

从 repo 中提取的样本:

https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences

ComicBook 是 Xamarin.Forms

提供者传统/标准

这些会让你知道怎么做。

【讨论】:

    【解决方案2】:

    *编辑:下面的 API 可能已随 Xamarin.Auth 1.5 更改。请参阅 moljac 的回答。

    对我来说,我使用活动来启动登录页面并传递上下文,但我也在 ContentPage 渲染器的 OnElementChanged() 方法中运行以下代码:

    Android.App.Activity activity = Context as Android.App.Activity;
    
    //Initialize authenticator
    
    activity.StartActivity(auth.GetUI(activity));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 2015-04-25
      • 2018-10-19
      相关资源
      最近更新 更多