Create user library for iOS - iphone

I am creating an 'SDK' which will enable communication with a piece of custom hardware (via BLE, abstracting my comm protocol to async methods/callbacks, on various classes all Obj-C). I wish to package this SDK so I can distribute it to users so they can build apps using this hardware. I want to provide an .h file(s) and a pre-compiled library (closed-source).
What's the best practice here? Shall I choose to create a .framework, .a, .dylib?
what's the difference between them and their usage cases? what's the correct way to create the needed library?
many thanks

You cannot create dylib for iOS. User cannot link his project with that library dynamically on iOS, it is platform restrictions.
You can create framework or .a file (static library).
There can be some issues with resources from you library (framework)
It is dublicate question, see Difference between framework and static library in xcode4, and how to call them

Related

When to use framework in Objective C development

Not many libraries such as GHUnit suggest you to use them as a Framework.
While most libraries such as Facebook iOS SDK just require you to drag the project into existing XCode project.
So when you are building a library which suppose to be re-use by other project in the future, should you use Framework or just like many current opensource projects, don't use Framework provided by XCode.
There is a reason why those opensource projects are provided as static libraries or just source code and not Framework, Frameworks are currently not supported by iOS SDK.
You can only use Frameworks provided by Apple - parts of SDK itself. Your code cannot be linked against your own or third party Frameworks.
So stick with one of those ways - I personally prefer static libraries.

Difference between static and dynamic library in Xcode for iPhone

What is the difference between a static and dynamic library in XCode? And why doesn't Apple allow us to use dynamic libraries in our iOS applications?
While you can build dynamic libraries for Mac OS X, you cannot use them for iPhone development.
A static library is merely an archive of object files that gets pulled into a program linking against it. The linker will unarchive all the archive files, and pull them in during linking along with the rest of your object files.
A dynamic library however, creates a shared object file, akin to a program but without an entry point, which programs can link against and call out of themselves into these shared libraries for their symbols, without pulling them into itself.
A dynamic library wouldn't make any sense for an iphone app as there is no way to install the library on the phone. I remember reading some documentation where apple stated they decided not to use dynamic libraries as they didn't want users to have to deal with hassles of finding/updating libraries. Much easier to just install 1 bundle per app.
Apple does allow you to make dynamic libraries. On Mac OS X, these end in .bundle or .dylib (not .so or .a like on Linux).
What, specifically are you trying to do? Did you create a target for your dylib?
iOS static vs dynamic library
Static library(.a) - library which copies all it's content into a target at compile time. That is why compile time is slower and result file is bigger, but there is no delay in run time
Dynamic library(.dylib) - library which has a single copy in a system where linking happens during run time. That is why compile time is faster, footprint of output file is smaller but there are some delays in runtime. Dynamic library is prerogative of OS(a lot of system libraries are dynamic) and as a developer you are not able to create it. Since such type of library is shared between different applications it should be secure and support IPC
Dynamic framework - framework with Dynamic library inside. Apple presented Dynamic framework and App extension[About] from iOS v8. You are able to use it inside single application to share common code and resources inside app sandbox
[Vocabulary]

Can I develop my own objective-C Framework for Cocoa Touch Applications?

Is it possible to create an own obj-C Cocoa Touch framework which can be used by other developers? And furthermore can you protect this framework?
I've created templates for Xcode 4 that allow you to build universal iOS frameworks (which work in both device and simulator).
Once the templates are installed, you simply select "Static iOS Framework" when creating a new project and it does the rest. It also works with unit tests.
https://github.com/kstenerud/iOS-Universal-Framework
You can create a static library. There is an option in the XCode project chooser to do this. You'll have to distribute the compiled static library file and the header files to users of your library. Your actual implementation files (.m) do not need to be distributed.
GHUnit does a good job of this - packaging up the libraries for both simulator and device - so I recommend looking at this project. (I also recommend using this library for unit testing :-)
The frameworks in Objective C are typically just C / ObjC code and a bunch of classes, nothing amazingly special. As such, you can create your own if you'd like, and then just include that in your project when you build it. The iPhone doesn't care about the difference, it just knows to put all that code into your app, along with everything else.
Have a look at the Framework Programming Guide on Apple's website. It will get you started. Essentially what you'll do is create a Framework project in XCode and then go from there.
As for "protecting" your framework, I assume you mean making your code unreadable. I'm not sure if and how you can do this, but perhaps Apple's guide will say something about it.
Yes you can create frameworks for use with Cocoa Touch.
However there are these caveats:
has to be a statically linked libary, no dynamic loading (dyld) for us
should be a combined (lipo) library for i386 (simulator), arm6 and arm7
you need to hack a bundle project into a framework
you should embed (small and few) images into the library so that the developer does not have to mess around with resources but just drags/drops it into his project
... or if you have large and many images build a bundle with these
I have guides for these things on my site.
1+2 = http://www.drobnik.com/touch/2010/04/universal-static-libraries/
The other links you have to google because this site does not let me post more than one URL.
You could make a static library available as binary (i.e. rudimentary "protection") to third parties, but not a dynamic one, as Apple's App Store policy prevents dynamic linking.
Take a look at a worked example for static libraries given at
this site
If you're going to do it, in my opinion JSON.framework is a great example to follow. To hide/obfuscate the source code is a different story, and a different question entirely,
When creating a new project, navigate to iOS > Framework & Library > Cocoa Touch Framework, it's as simple as that. When you are successfully compile, .framework will be created under Products folder in XCode. Right click to show in Finder, and you can find the output.
It's unlikely this will work the way you want it to because the other developers won't be able to use your framework. This StackOverflow Question explains why.

How to develop distributable UI controls for iPhone?

I would like to develop a reusable UI control for iPhone. How should I go about doing this? When I say reusable I mean it's packaged in a dll (or whatever is used on iPhone platform) so it can be reused on multiple projects.
While dynamic libraries are not allowed to be used in iPhone applications that are to be sold on the iPhone App Store, here's a tutorial on building static libraries with the iPhone SDK. (assuming you don't want to release source code)
You have two options:
Supply the full source code. Other developers can then add it directly to their app.
Distribute the compiled version of your code as a static library.
As you're planning to develop a UI control, I suggest you also develop an IB plugin and ship that with it too.
You probably want to provide custom Interface Builder objects, or maybe source code libraries.
Well, the Xcode way would be to bundle your code into a Framework and link to that. However, under the iPhone you can't link to non Apple approved frameworks (even if they are your own)
So you would probably have to link in the source to the reusable code. A good article here

Using a custom framework

The error I'm getting:
in /Users/robert/Documents/funWithFrameworks/build/Debug-iphonesimulator/funWithFrameworks.framework/funWithFrameworks, can't link with a main executable
Cliff notes:
trying to include framework
doesn't want to link
More detail:
I'm developing for a mobile device... hint, hint using Xcode and I'm trying to make my
own custom framework which I can include from another application. So far, I've done the following:
Create a new project; an iPhone OS window based app.
Go to target info-> under packaging, change the wrapper extension from app to framework
Go to Action->new build phase -> copy headers. Change roles of headers to 'public'
From my application, I add the framework to the frameworks group.
Apple clearly said that you can not use dynamic libraries on their mobiles. And a private framework is just this.
You can, however, use static libraries.
Egil, that's usually considered as one of the implications of section 3.3.2 of the iPhone developer agreement, which (in part) forbids plug-in architectures or other frameworks. The fact that they don't provide an Xcode project template for an iPhone-compatible framework tends to reinforce the idea, though of course it could just be an oversight or something they're discouraging without actually forbidding.
Whether this is the intended meaning of that section is something you'd have to ask Apple about, and possibly consult a lawyer, but this is where the oft-stated "no frameworks" idea comes from.
For those who have framework code they'd like to use in an iPhone app, an alternative approach is to use the framework code to build a static library. That then gets compiled into the application instead of getting dynamically loaded at run time. The fact that it's part of the application executable avoids any potential concerns about this part of the agreement.
Though dynamic libraries are not allowed, you CAN create a framework (using static libraries and lipo).
Check out: http://accu.org/index.php/journals/1594
I haven't tried it for so called mobile device, but I would guess its very similar to the method for a regular Cocoa application. Check out this tutorial:
Embedded Cocoa Frameworks