1.设置URL scheme
identifier随意取,URL scheme随意取,和别的App别重复。

2.Appdelegate实现application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
方法
//支付宝支付
if url.host == "safepay" {
//跳转支付宝钱包进行支付,处理支付结果
AlipaySDK.defaultService().processOrder(withPaymentResult: url, standbyCallback:nil)
//授权跳转支付宝钱包进行支付,处理支付结果
AlipaySDK.defaultService().processAuth_V2Result(url, standbyCallback:nil)
}
else{
WXApi.handleOpen(url, delegate: self)
}
return true
}
注意:
如果此处的standbyCallback有回调内容,则执行此处的回调,第3步中支付代码中的callback回调不会执行。
如果App中集成了微信登录,一定要实现
WXApi.handleOpen(url, delegate: self)
,否则微信登录会报错PBItemCollectionServicer connection disconnected.
,收不到微信登录的结果。若使用SceneDelegate,AppDelegate里面的openUrl...options方法不执行
需要在SceneDelegate里面设置:
@available(iOS 13.0, *)
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if URLContexts.first!.url.host == "safepay" {
AlipaySDK.defaultService().processOrder(withPaymentResult: URLContexts.first!.url, standbyCallback:nil)
AlipaySDK.defaultService().processAuth_V2Result(URLContexts.first!.url, standbyCallback:nil)
}
}
网友评论