使用 c/c++使用 iPhone 应用程序目标 c 网络的库
我目前正在评估 ac/c++ 库是否可以用于我的特定 iPhone 项目。原始库大量使用了 Windows 特定代码(例如,它包括 windows.h 和 Winsock.h)。我知道我将不得不重写使用 Windows 特定代码的部分,并用 bsd 套接字等替换winsocks。或者尝试转换为 Objective-C++ 并使用 iOS 特定的网络 api,如 Apple 文档中建议的那样。
但正如 Apple 文档中所表明的那样,在 iOS 中,仅允许使用 C 和 Objective-C 代码进行网络连接。 “iOS 支持用 C 和 Objective-C 编写的网络代码。” ( https://developer.apple.com/library/ios/# Referencelibrary/GettingStarted/GS_Networking_iPhone/ )
听起来我必须用 Objective-C 重写整个库才能使其在 IOS 上运行。或者在 Objective-C 中编写一个包装类并使用原始(适用于 bsd 套接字 api 或 Objective-C++)库就足够了吗? -> 使用 iPhone ObjectiveC 应用程序中的 C/C++ 静态库
但实际的网络代码仍然是用 c/c++ 而不是 Objective-C 编写的。
这有可能起作用吗?我不想完成所有适应库的工作,然后发现这种方法不起作用。
以前有人尝试过类似的东西吗?
此致, 麦克风
I am currently evaluating if a c/c++ library may be used for a specific iPhone project of mine. The original library makes heavy use of windows specific code (for example it includes windows.h and winsock.h). I am aware that I will have to rewrite the parts that use windows specific code and replace winsocks with for example bsd sockets. Or try to convert to objective-c++ and use IOS specific networking apis as it's recommended in Apple's documentation.
But as it turns out in Apple's documentation, in iOS only C and Objective-C code is allowed for networking. "iOS supports networking code written in C and Objective-C." ( https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/GS_Networking_iPhone/ )
That sounds like I have to rewrite the whole library in objective-c to make it work on IOS. Or would it be sufficient to programm a wrapper class in objective-c and work with the original (adapted to bsd sockets api or objective-c++) library? -> Using C/C++ static libraries from iPhone ObjectiveC Apps
But the actual networking code still would be written c/c++ not objective-c.
Is there any chance this might work? I don't want to do all the work of adapting the library and then notice that this approach does not work.
Has anyone tried something similiar before?
Best regards,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够将 C++ 库的部分内容重写为使用 BSD 套接字而不是 Windows 套接字 API,不会出现任何问题。
Apple 并不禁止 C++ 代码访问网络,但是 iOS 提供的唯一网络 API 是 C(BSD 套接字、CoreFundation)或 Objective-C(Foundation...),也许这就是您困惑的根源。您可以在自己的代码或静态链接库中自由混合 C、C++ 和 Objective-C 代码。
You should be able to rewrite portions of your C++ library to used BSD sockets instead of the Windows sockets API without any problems.
Apple does not forbid C++ code from accessing the network, however the only networking APIs offered by iOS are in either C (BSD sockets, CoreFundation) or Objective-C (Foundation…), perhaps that's the source of your confusion. You can freely mix C, C++ and Objective-C code in your own code or in statically linked libraries.