ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2020-03-08 13:03:01  阅读:365  来源: 互联网

标签:iOS13 微信 scene application window openSDK1.8 SceneDelegate


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,加入进来即可

 下面是具体的实现:

  

 

 

 

  • 在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
        }
    

      

标签:iOS13,微信,scene,application,window,openSDK1.8,SceneDelegate
来源: https://www.cnblogs.com/jiduoduo/p/12442070.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有