iOS13 微信支付openSDK1.8.6 回调失败

IDE及测试环境

xcode 11.3.1(11C504)

iPhone设备:iOS13.3.1

微信 v7.0.11

 

问题描述

集成微信支付已经成功,但是不走回调,也就是说APP不能立即知道是不是支付成功了。

好些场景情况下,我们是要作些处理的,这样更加的提高用户的体验,比如说充值,我们需要立即给用户的余额加上。

 

解决方法

1)在iOS13中,引入了分屏,这个是之前没有的,当您用xcode11建一个新的工程的时候,会发现多了一个SceneDelegate文件,这个文件就包括了场景Scene

这里面可以建window对象,也就是说这个从AppDelegate中分离出来了,目的就是为了支持分屏。

这种情况下,微信支付回调,会走SceneDelegate

2)那么如何处理呢,有些设备因为比较老,还不是iOS13,比如iOS12等等,有些微信的版本并没有超过7.0.5,那么微信支付还是会走AppDelegate

3) 这样的话,我们既要满足iOS13, 又要满足之前的版本,可以作以下处理:

   3.1)加入版本判断

   3.2)将以前不支持的SceneDelegate,加入进来即可

 下面是具体的实现:

  iOS13 微信支付openSDK1.8.6 回调失败

 

 

 

  • 在AppDelegate加入方法,让AppDelegate知道有SceneDelegate
  •     //这个方法就是将SceneDelegate关联起来
    @available(iOS 13.0, *) func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) }
    //这个方法也可以不加 @available(iOS 13.0, *) func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. }

    //这个方法加一个if,通过不同的版本来干不同的活。

  • func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            //注册微信打印日志
            WXApi.startLog(by: WXLogLevel.init(rawValue: 1)!) { (msg) in
                print(msg)
            }
            //注册APPID
            let result = WXApi.registerApp(WX_APPID, universalLink: WX_UniversalLink)
            print(result)
            
            if  #available(iOS 13.0, *)  {
                print("如果是iOS13,那么进入scene")
            }else{
                window = UIWindow()
                window?.frame = UIScreen.main.bounds
                window?.rootViewController = ViewController()
                window?.makeKeyAndVisible()
            }
            
            return true
        }
    

      

上一篇:Kafka与RabbitMQ对比


下一篇:7. (代码为临时性二维码获取的案列)微信公众号二维码的获取