Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using c/c++ library that uses network for iphone app 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

like image 655
Michael Klein Avatar asked Nov 22 '10 15:11

Michael Klein


1 Answers

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.

like image 108
Julio Gorgé Avatar answered Sep 19 '22 16:09

Julio Gorgé