首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将茜素iOS转化为茜素macOS

将茜素iOS转化为茜素macOS
EN

Stack Overflow用户
提问于 2017-11-09 23:33:40
回答 1查看 175关注 0票数 2

我使用下面的类在iOS中进行身份验证,但由于SFSafariViewControllerSFSafariViewControllerDelegateUIViewController无法解析,所以无法使用Xamarin macOS。

有人能帮助我替换这些类,以便在Xamarin macOS应用程序中使用这些类吗?

代码语言:javascript
复制
public class PlatformWebView : SFSafariViewControllerDelegate, IBrowser
    {
    private SafariServices.SFSafariViewController m_Safari;
    private readonly UIViewController r_Controller;

    public PlatformWebView(UIViewController i_Controller)
    {
        r_Controller = i_Controller;
    }

    public override void DidFinish(SFSafariViewController i_Controller)
    {
        ActivityMediator.Instance.Send("UserCancel");
    }

    public Task<BrowserResult> InvokeAsync(BrowserOptions i_Options)
    {
        if (string.IsNullOrWhiteSpace(i_Options.StartUrl))
        {
            throw new ArgumentException("Missing StartUrl", nameof(i_Options));
        }

        if (string.IsNullOrWhiteSpace(i_Options.EndUrl))
        {
            throw new ArgumentException("Missing EndUrl", nameof(i_Options));
        }

        // must be able to wait for the intent to be finished to continue
        // with setting the task result
        TaskCompletionSource<BrowserResult> tcs = new TaskCompletionSource<BrowserResult>();

        // create Safari controller
        m_Safari = new SafariServices.SFSafariViewController(new NSUrl(i_Options.StartUrl));
        m_Safari.Delegate = this;

        ActivityMediator.MessageReceivedEventHandler callback = null;
        callback = async (i_Response) =>
        {
            // remove handler
            ActivityMediator.Instance.ActivityMessageReceived -= callback;

            if (i_Response == "UserCancel")
            {
                tcs.SetResult(new BrowserResult
                {
                    ResultType = BrowserResultType.UserCancel
                });
            }
            else
            {
                // Close Safari
                await m_Safari.DismissViewControllerAsync(true);

                // set result
                tcs.SetResult(new BrowserResult
                {
                    Response = i_Response,
                    ResultType = BrowserResultType.Success
                });
            }
        };

        // attach handler
        ActivityMediator.Instance.ActivityMessageReceived += callback;

        // launch Safari
        r_Controller.PresentViewController(m_Safari, true, null);

        // need an intent to be triggered when browsing to the "io.identitymodel.native://callback"
        // scheme/URI => CallbackInterceptorActivity
        return tcs.Task;
    }
}

public class ActivityMediator
    {
    public delegate void MessageReceivedEventHandler(string i_Message);

    private static ActivityMediator s_Instance;

    public static ActivityMediator Instance
    {
        get
        {
            if (s_Instance == null)
            {
                s_Instance = new ActivityMediator();
            }

            return s_Instance;
        }
    }

    private ActivityMediator()
    {
    }

    public event MessageReceivedEventHandler ActivityMessageReceived;

    public void Send(string i_Response)
    {
        ActivityMessageReceived?.Invoke(i_Response);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-10 01:38:28

"SafariServices“在macOS上不可用。

WebKit的WKWebViewWebView是,如果你的目标是OSX10.10及以上,苹果建议使用WKWebView

re:https://developer.apple.com/documentation/webkit/wkwebview?language=objc

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47213403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档