【问题标题】:Unable to redirect to the authentication page using Xamarin.OAuth 2.0无法使用 Xamarin.OAuth 2.0 重定向到身份验证页面
【发布时间】:2018-03-28 11:13:13
【问题描述】:

目前我正在使用 Xamarin 表单来创建 Android 和 iOS。现在我使用 OAuth2.0 进行登录功能。所以我在 Xamarin iOS 项目中创建了一个视图控制器。在 AppDelegate 类中,我从 FinishedLaunching 方法调用我的控制器视图。

喜欢:

var mainController = new ViewController(); // Your view controller here
 mainController.ViewDidLoad();

在ViewDidLoad中写了OAuth2.0的逻辑并使用了 this.PresentViewController(authGui, true, null)。但在我的项目中,它没有重定向到页面并给出以下警告

Warning: Attempt to present <UINavigationController: 0x7fde4a9d6800> on
<ViewController: 0x7fde4a53f9d0> whose view is not in the window hierarchy!

【问题讨论】:

标签: ios xamarin oauth-2.0 xamarin.ios native


【解决方案1】:

无需手动触发ViewDidLoad() 事件。我们假设您使用空白应用程序模板。您应该设置WindowRootViewController 来显示它,然后ViewDidLoad() 事件将触发。更多详情请阅读this documentation 了解iOS UIViewController,另请参阅this post 了解UIViewController 的生命周期。

将这个mainController 带入Window 后,您可以使用this.PresentViewController(authGui, true, null) 在屏幕上呈现OAuth 视图

Authenticating Users with an Identity Provider 告诉你如何在每个平台上实现OAuth,你应该仔细阅读。除了在 iOS 上,如果您想重定向回您的应用,请在 Info.plist 中设置自定义 URL 方案。当它返回时,将调用事件OpenUrl(),在AppDelegate.cs 中覆盖它。

【讨论】:

    猜你喜欢
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多