【发布时间】:2019-07-14 21:56:18
【问题描述】:
我正在处理原生脚本应用程序中的一些 SSO 行为。我有以下可以正常工作的 Swift 代码:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
var webAuthSession: SFAuthenticationSession?
@IBAction func click(sender: AnyObject)
{
let authURL = URL(string: "http://localhost:5000/redirect.html");
let callbackUrlScheme = "myApp://"
self.webAuthSession = SFAuthenticationSession.init(url: authURL!, callbackURLScheme: callbackUrlScheme, completionHandler: { (callBack:URL?, error:Error?) in
// handle auth response
guard error == nil, let successURL = callBack else {
return
}
print(successURL.absoluteString)
})
self.webAuthSession?.start()
}
}
从这里我想出了等效的打字稿代码(在 .ios.ts 文件中)
function callback(p1: NSURL, p2: NSError) {
console.log('Got into the url callback');
console.log(p1);
console.log(p2);
};
public onTap() {
const session = new SFAuthenticationSession(
{
URL: NSURL.URLWithString('localhost:3500/redirect.html'),
callbackURLScheme: 'myApp://',
completionHandler: callback,
},);
console.log('session created');
console.log('the session is ', session);
console.log('the start method is ', session.start);
console.log('about to call it');
session.start();
console.log('After calling start');
}
这一切都可以正常编译和构建,但是在运行时它会在大约一秒左右的延迟后在 session.start() 调用中崩溃。在此之前我得到了输出,包括“即将调用它”方法,但之后什么都没有,甚至没有错误消息或堆栈转储。
这里有什么明显的我做错了吗?从 typescript 调用原生 ios 共享库方法需要做些什么特别的事情吗?
【问题讨论】:
标签: nativescript sfauthenticationsession safariservices