Using 3rd party framework for IOS in Delphi Firemonkey - ios

I need to use SendAnywhere SDK (github.com/estmob/SendAnywhere-IOS-SDK) for IOS in Delphi Seattle (www.embarcadero.com/products/delphi). I have to convert obj-c code into delphi, like Embarcadero did that with native frameworks.
I have already read these articles:
The quest to migrate iOS SquareCam App to Firemonkey
Delphi for iOS - some notes
They are the most complete guides for using native frameworks. But what about 3rd party?
What folders have I to put downloaded from GitHub files in?
There is an static .a library in SDK. How to include/import/use/open it in a FMX project?
Or I need to create my own static library from this SDK. But How?
Where to start from?

If you have a framework file it usually includes a set of header files and a static library. You can extract the static library (the file with the same name as the framework) and rename it by adding an '.a' extension. You can then use that file directly your Delphi project. I have done this with XE8 to X10.
Simply put the static library in your path when you build and you also need to trick the Delphi compiler to link it. Just add a line of code to your implementation section of your unit such as:
procedure LibWhatever2; cdecl; external 'libWhatever.a' name 'OBJC_CLASS_$_SomeClassName'

Related

How to add 3rd-Party Framework to Delphi iOS Project?

I need to use Wacom Bluetooth Stylus SDK to a FireMonkey Project (iOS) in Delphi 10.4. This framework includes the framework (obvious) and a '.bundle' resources. How do I add these framework to the project in order to use its classes and methods?
Thank you.
You need to run the framework through a transform tool which will generate the pascal header files for you and give you access to the classes you need.
https://community.idera.com/developer-tools/b/blog/posts/quickly-auto-generate-ios-osx-and-android-headers-for-delphi-and-c-builder
This tool is the best available for iOS but requires a bit of setup in terms of where to put your framework file (it needs to be in the same folder as the iOS SDK files Delphi uses) and the location of clang etc. The above article is helpful for this.
After being generated you then need to link in your .a framework file which is usually the file in the framework bundle with the same name as the framework but no extension. Just rename with a .a extension.
Linking in can be done two ways - statically by adding into the linker options field under the compiler section of your profile (you may need a -objc parameter too) or you can lazy reference it in your code so the compiler automatically pulls it in.
This SO reference explains the fake loader concept:
How to use 3rd party framework depends from dylib for IOS in Delphi Firemonkey
It can be a little bit of a black art to get it working as the error messages are vague if it goes wrong but hopefully the above helps.

how to create dynamic library for ios project in xcode?

I am new to xcode please can anyone tell how to create dynamic library for an ios project similar to (.so) files in android? I have found .dylib files for Os x but haven't found anything for ios.
Go here. There is a section for how to make frameworks with C++ code. Basically, you need to make C wrappers for your C++ interface, because of name mangling done by the C++ compiler.

Can I make iOS all-in-one framework? or include private static library into my framework?

I'm a novice on XCode and I'm making an iOS Framework with Swift2, including 3rd party libraries(*.a) and frameworks.
I want to provide it as API to others, but I also want to hide the 3rd party libs and frameworks files from my framework distribution files because they are private.
Therefore I just want to open API interfaces and classes I defined.
Is it possible? How to configure my build options?
You can do that but there are some things you need to consider:
You cannot embed one framework into another one. That means if you do not have the sources to a particular framework you have to ship it alongside your own framework. If you have the sources you may consider compiling them into your framework directly.
Depending on the sources that you use in the framework you might have to do some post processing of the framework to obfuscate private headers etc. For example, if you use Objective-C or C code alongside Swift you definitely need to do some post processing of your *.framework file to hide any API that you want to keep private.
If you use Swift code in your framework please be aware that your framework can only be used by someone with the same Swift compiler version due to the absence of an ABI. That means binaries produced by one compiler version have a high likelihood of being incompatible to a newer version of the compiler.
Static linked libraries can be linked and therefore "merged" into your framework binary directly. You just need to make sure that you have a compatible binary for the architecture you want to target, e.g., you cannot use a static linked library that was build for simulator and link it against your framework that you want to build for the actual iOS device.
If you use Swift in your framework, the users of your framework need to include the Swift dylib libraries in their app bundle - either by using Swift in the app or by enabling the Embedded Content Contains Swift Code build setting.

How to use 3rd party framework depends from dylib for IOS in Delphi Firemonkey

I'm using 3rd-party SDK, presented as libXXX.a, that needs
libstdc++.dylib
libz.dylib
15/05/2017 ANSWER.
Finally I have found a time to write down my solution.
If your 3rd party SDK depends from some dynamic libraries, do this:
For example dynamic library is called as "libSuperLibrary.dylib".
For example 3rd party SDK is called as "SuperFramework.framework".
Go to "Project - Options - Delphi Compilier - Framework Search Path"
Fill the field by path to your framework like "C:\path\to\my\frameworks\"
Go to "Project - Options - Linking - Options passed to the LD linked"
Fill the field by string "-ObjC -framework SuperFramework -lSuperLibrary
Compile
IOS does not allow dynamic libraries. When building with XCode it automatically links the needed static libraries, but only in the final app, not if you build a static library. Instead you can tell Delphi to handle the dependencies.
In the pascal header file for libXXX.a (where you import the functions to Delphi) add dependency like this:
function MyFunction; cdecl; external libXXX.a name 'myfunction' dependency 'stdc++'
I have used it my self with 'c++' (which corresponds to 'libc++.dylib') and 'stdc++' (corresponds to 'libstdc++.dylib'), but you will have to try your self if it works with the z library.
Read more here:
http://docwiki.embarcadero.com/RADStudio/Seattle/en/Procedures_and_Functions#Specifying_Dependencies_of_the_Library

How to create static library from an existing framework in iOS?

I have been provided with a framework by a third party vendor for an iPhone hardware accessory. So I have a folder like Device.framework. Inside that folder is a binary file and a set of .h files. There are instructions for how to add this to an iOS project and use the classes contained within. However, I'm actually using MonoTouch and want to use a static library.
Is there a way to create a static library that makes all the classes from the framework available in the static library? So in my MonoTouch project I would link in the static library and have access to that framework.
A *.framework is simply a package containing: the static library, headers, associated meta data. Copy and paste the .framework and extract the static *.a file and related header files.
Then it's simply a matter of using the MonoTouch btouch tool to bind the static library for use in your MonoTouch project. There is a great example of how to bind a native library to MonoTouch on Github. With guidance on targeting simulator + device and using the LinkWith attribute to embed the static library in a single *.dll:
https://github.com/xamarin/monotouch-samples/tree/master/BindingSample
Also, make sure to check out the btouch Reference documentation here:
http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types
Rename that binary file to Device.a. You can do that as the framework you mention is not done by Apple, hence it has to be a static library and not a dynamic one.
Make sure your project links that library (Device.a).
Include the headers in your project and reference them where appropriate.

Resources