func application(_ application: NSApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool {
// wechat sdk handle, replace self with object implement WXApiDelegate
WXApi.handleOpenUniversalLink(userActivity, delegate: self)
return authgear.application(application, continue: userActivity, restorationHandler: restorationHandler)
// If your app has opted into Scenes, Update Scene Delegate
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
// wechat sdk handle, replace self with object implement WXApiDelegate
WXApi.handleOpenUniversalLink(userActivity, delegate: self)
authgear.scene(scene, continue: userActivity)
// Implement WXApiDelegate
extension MyClass: WXApiDelegate {
func onReq(_ req: BaseReq) {}
func onResp(_ resp: BaseResp) {
// Receive code from WeChat, send callback to authgear
// by calling `authgear.wechatAuthCallback`
if resp.isKind(of: SendAuthResp.self) {
let _resp = resp as! SendAuthResp
if let code = _resp.code, let state = _resp.state {
authgear.wechatAuthCallback(code: code, state: state) { result in
// send wechat auth callback to authgear successfully
case let .failure(error):
// failed to send wechat auth callback to authgear
// failed to obtain code from wechat sdk