【发布时间】:2019-08-26 18:32:51
【问题描述】:
将以下 swift 示例中的代码转换为 C# (Xamarin) 以在 SFSafariViewController 中收到 Paypal 令牌但不触发该方法时通知应用程序。
如下所示将 swift 转换为 C#,但在用户登录 PayPal 并收到令牌后,Safari 不会关闭以触发 SetupMerchant()
UrlSchemes 也设置为 Retailsdksampleapp 以匹配来自 PayPal 的示例 swift 应用程序。
SafariDelegate safariDelegate = new SafariDelegate(this);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("kCloseSafariViewControllerNotification"), safariDelegate.SetupMerchant);
void loadBrowser()
{
var url = new NSUrl("https://paypalauth.herokuapp.com/toPayPal/" + Application.paypalEnvironment + "?returnTokenOnQueryString=true");
var svc = new SFSafariViewController(url);
svc.Delegate = safariDelegate;
this.PresentViewController(svc, true, null);
}
public class SafariDelegate : SFSafariViewControllerDelegate
{
ViewController _controller = null;
public SafariDelegate(ViewController controller)
{
_controller = controller;
}
public void SetupMerchant(NSNotification notification)
{
// Dismiss the SFSafariViewController when the notification of token has been received.
this._controller.PresentedViewController?.DismissViewController(true, () => { });
// Grab the token(s) from the notification and pass it into the merchant initialize call to set up
// the merchant. Upon successful initialization, the 'Connect Card Reader' button will be
// enabled for use.
var accessToken = notification.Object.ToString();
}
}
从 Paypal 运行 swift 示例应用程序时,它会在登录后关闭浏览器 (SFSafariViewController) 并触发 SetupMerchant() 但不在 C# 代码中。可能是缺少步骤或代码转换无效。
【问题讨论】:
标签: c# xamarin paypal sfsafariviewcontrollerdelegate