Using c/c++ library that uses network for iphone app objective c - iphone

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

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.

Related

Is it possible to use some C source code in iPhone project?

I found a speech synthesizer that supports many languages (http://espeak.sourceforge.net/index.html). But the source code that is available is written in C.
What can i do to make it work on iPhone?
Objective-C is a strict super set of C. Which means you can use any C code in your Obj-C project.
Yes, as long as it's been ported to the LLVM C-compiler. You can create a statically linked framework out of it, and then link into your project.
Apple does not allow dynamically-loaded frameworks.

Objective-C++ for iOS development

Is it possible to use Objective-C++ for iOS application (iPhone, iPad, iPod touch) development?
Are there any examples and source code on the Internet?
Using ObjC++ is quite easy.
You have to declare source files with extension .mm. It will make compiler treat them as ObjC++. The same with headers: use the .hh extension.
There is another option: go to target settings and set Compile Sources As to Objective-C++.
That's all. No additional work is necessary.
Some notes: if you want to develop a native iOS app, then use Objective C. It will save a lot of time.
But in some cases using C++ is more appropriate. E.g. for cross-platform development. So you use only a little bit of Objective C for iPhone or Java for Android just to glue your code with environment. Everything else in C++. I use this for my cross-platform game development.
Another case is performance: Objective C is principally slower then C++. However it is only noticeable during method calls (in ObjC it is called messaging).
Yes, you can. Take a look at the samples and new file templates that Apple provides.

Is TA-lib.org support on iOS on iphone?

I would like to add Technical analysis support to my financial project on iphone. And I found TA-lib on www.ta-lib.org, this library supports many indicators I need.
I would like to ask: Can I use ta-lib on my iphone development? And how I can do it, because this library is written in C language? I knew that Cocoa can compile C but how I can do it, import this library to iOS?
Any help would be appreciated.
Thanks
The iPhone SDK tools will compile most portable C code just fine (C is a pure subset of Objective C). There appears to be C source code available for the library in which you're interested. If so, you could try just including the source to the library in your iPhone Xcode project, and see if it all compiles, which it might if there are no dependency or collision problems. You may or may not need the entire library, which might help simplify things (or not).
You could also compile a separate static library, and then include that library, and the headers, in your iPhone app; but that technique may be a bit more complicated that your requirements might indicate.

Which is the most supported programming language for the iPhone?

I have decided to start programming some apps for the iPhone that eventually will get submitted to App Store. So I have to use a language the Apple supports.
However, from what I understand, there are some variety of languages I can choose from.
Ansi C
Objective C
C
C++
I started learning C++ in school back in 2001, so maybe I should use that. However, I would like to use the language that is most supported API and community wize. Which one is that?
Here's the low-down:
All iPhone SDK APIs are either Objective-C or pure (ANSI) C. The pure C APIs tend to be the lower-level APIs, so you could use just Objective-C.
However Objective-C is a strict superset of C, so you'll need a reasonable grounding in C in order to write Objective-C.
C++ is fully supported, but is not required (there are no C++ APIs). You can even mix Objective-C and C++ in the same source using Objective-C++. If you do this it's best to use C++ for pure computational components, pure Objective-C for the front-end, and Objective-C++ for the "glue" layer in the middle.
In summary: you'll need C and Objective-C. Use C++ for some parts if you particularly need it.
objective-c is the most supported - all the examples use it
Main language for iPhone platform is objective-c - almost all frameworks are objective-c based so you will have to use it for UI part at least. However as objective-c is a superset of c language you will be able to write some parts of your program using c/c++ as well.
There are C and Objective-C frameworks. Quartz2D is written in C but the Cocoa Touch framework is written in Objective-C, for instance. As Objective-C is a superset of C, if you choose Objective-C you will be able to use all available frameworks without problems.
Depending on what type of applications you're gonna to write, you could save yourself a lot of time & headache and use Appcelerator's Titanium Mobile (JavaScript) or Rhomobile (Ruby). All according to Apples latest TOU and therefore still submittable to the App Store.
The only languages that are officially allowed by Apple are
JavaScript
Objective-C
C++
C
All other languages are not allowed.
Whether or not this restriction is legal is a totally different question. (My gut feeling says that, at least in countries with somewhat sane anti-trust laws, it's illegal.)

How do I interface OCaml with iPhone API?

I'd like to start developing applications for iPhone, but I'd really like to use OCaml rather than Objective-C. After some googling, it seems like this is definitely possible, but I haven't found any code snippets which actually compile.
Is it possible to write iPhone apps using OCaml? If so, could you provide a snippet demonstrating how to make calls into the Cocoa API from OCaml?
We have instructions for building an OCaml-to-iOS cross compiler on our site. We started with the patches mentioned above, but we found they needed to be modified in several ways to run on a stock iPhone/iPad. We are selling an iPhone app named Cassino that is entirely written in OCaml (except for thin wrappers to Cocoa Touch). Wrappers for all of Cocoa Touch would be a big job, but wrappers for a single application aren't so bad. And coding in OCaml is very pleasant compared to ObjC.
We also just published full sources for a small OCaml iPhone app named Portland at our site. Read more at psellos.com.
Out of the box, OCaml cannot be used to build IPhone apps. You would have to have OCaml output ARM code rather than x86 code. You would also have to build wrappers for all the IPhone API calls.
Still, these guys are going through the pain to try this.
http://web.yl.is.s.u-tokyo.ac.jp/~tosh/ocaml-on-iphone/
My humble recomendation is that you focus on using Obj-C for everything. If
you really want an ML, use it only for the kernel or the interesting portion.
I would find an *ML that code gens to something like C, and then use that result
as a library to the app.
Good luck.