简体   繁体   English

如何在swift项目中集成PayUMoney iOS SDK?

[英]How to integrate PayUMoney iOS SDK in swift project?

I'm developing an ecommerce iOS app in swift.我正在快速开发一个电子商务 iOS 应用程序。 I want to integrate PayUMoney iOS SDK into my project.我想将 PayUMoney iOS SDK 集成到我的项目中。 Only Objective-C SDK is there.只有 Objective-C SDK 存在。 All SO questions, tutorials and documentations are in Objective-C only.所有 SO 问题、 教程文档仅在 Objective-C 中。 Is there any way to integrate this SDK into swift project?有什么办法可以将这个 SDK 集成到 swift 项目中吗? Please help me.请帮我。

To integrate Obj-C libraries into a Swift Project all you have to do is use a so-called Bridging Header .要将Obj-C库集成到 Swift 项目中,您所要做的就是使用所谓的Bridging Header Those literally work as bridge between the Obj-C code and the Swift code.这些实际上是Obj-C代码和Swift代码之间的桥梁。 Here is an exact representation from the Apple Docs:这是 Apple Docs 中的确切表示: 解释 Basically what this does it let's Swift access everything through the one header file and for Obj-C it generates a .m file with all methods and other code.基本上,它的作用是让 Swift 通过一个头文件访问所有内容,而对于 Obj-C,它会生成一个包含所有方法和其他代码的 .m 文件。

  1. To add a bridging header, simply create a new File -> iOS -> Source -> CocoaTouch -> UIViewcontroller and then as language select Objective-C .要添加桥接头,只需创建一个新的File -> iOS -> Source -> CocoaTouch -> UIViewcontroller然后选择Objective-C作为语言。 You can name it yourNewlyCreatedClass for example.例如,您可以将其命名为yourNewlyCreatedClass whatever you want as we'll later delete it.任何你想要的,因为我们稍后会删除它。
  2. Once you do that you will get this Pop Up:一旦你这样做,你会得到这个弹出窗口: 弹出 asking you if you want to create the bridging header.询问您是否要创建桥接头。 Select the create function and open the newly created file that should be named something like Briding-Header.h选择创建函数并打开新创建的文件,该文件应该命名为Briding-Header.h
  3. Now, you can remove the line that say #import "yourNewlyCreatedClass.h" and replace it with #import <PayUMoney/PayUMoney.h> or whatever the framework is called.现在,您可以删除说#import "yourNewlyCreatedClass.h"并将其替换为#import <PayUMoney/PayUMoney.h>或任何框架调用。
  4. To finish up, you can now delet the two created classes from before.最后,您现在可以删除之前创建的两个类。 Simply select yourNewlyCreatedClass.h and yourNewlyCreatedClass.m and you're good to go.只需选择yourNewlyCreatedClass.hyourNewlyCreatedClass.m就可以了。

    Congrats, now you can access any of the methods you see in their docs through simply typing them in your swift file.恭喜,现在您只需在 swift 文件中键入它们,就可以访问您在他们的文档中看到的任何方法。

For further reference, please advise the Apple Docs found here .如需进一步参考,请告知此处的 Apple 文档。 Images were used from the official Apple Docs.图片来自官方 Apple Docs。

Hope that helps, Julian希望有帮助,朱利安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM