Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not really disagreeing with <a href="https://stackoverflow.com/a/4733885/168740">DarkDust's answer</a>, but if I may channel my inner Bill Clinton, <a href="http://www.slate.com/articles/news_and_politics/chatterbox/1998/09/bill_clinton_and_the_meaning_of_is.html" rel="noreferrer">it depends on what the meaning of <em>supported</em> is</a> :)</p> <p>Apple doesn't want you doing this for App Store apps, but the operating system certainly allows it. Jailbreak apps use this technique all the time. You basically use a standard UNIX technique to dynamically open a framework/library, and then use stuff in it. The <a href="https://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlopen.3.html" rel="noreferrer">dlopen function</a> allows you to open the library by passing in <a href="https://stackoverflow.com/a/10859489/119114">the path to that framework</a>, or dylib. From some <a href="http://thebigboss.org/hosting-repository-cydia/submit-your-app/compile-for-cydia-submission" rel="noreferrer">docs for building jailbreak apps</a>, here's an example of calling an <code>init()</code> function implemented inside your own, separate dylib:</p> <pre><code>#include &lt;dlfcn.h&gt; initWrapper() { char *dylibPath = "/Applications/myapp.app/mydylib2.dylib"; void *libHandle = dlopen(dylibPath, RTLD_NOW); if (libHandle != NULL) { // This assumes your dylib’s init function is called init, // if not change the name in "". void (*init)() = dlsym(libHandle, "init"); if (init != NULL) { init(); } dlclose(libHandle); } } </code></pre> <p>Furthermore, the default restriction against allowing you to <strong>build</strong> a dynamic library project for iOS is something in XCode that you have the ability to override by editing some XCode xml files: </p> <p><a href="http://blog.iosplace.com/?p=33" rel="noreferrer">Build and use dylib on iOS</a> </p> <p>Once you do this, you can build a normal iOS <strong>.dylib</strong> library, and use it per the sample code above. (yes, you probably will have to unlock this capability again whenever you install a new XCode version).</p> <p>So, it's not a technical limitation, but an App Store policy limitation. If you're not limited to the App Store, then you can do it. Note that this technique does <strong>not</strong> require jailbreaking, although if the app is sandboxed, it may limit <em>where</em> dylibs can be loaded from.</p> <p><br/><br/></p> <p><strong>Edit:</strong> in order to make sure this information isn't lost to future link rot, here is the content of the link I provided on how to enable iOS dylibs in Xcode. (<strong>Note:</strong> this process still works on Xcode 4, but see comment(s) below for updates to paths, etc.) Source is the <a href="http://blog.iosplace.com" rel="noreferrer">iOS Place blog</a>:</p> <hr> <p>Xcode does not allow you to build dylib for iOS. App will be rejected if it’s not single binary. But I have an application that has plug-in architecture to load optional modules. I just want a quick prototype to prove concept before fully port it to iOS. It’s faster to do if dylib could simply work. So, this post shows how to build and use dylib but be aware it won’t be approved to App Store. (Tested with Xcode 3.2.4 on 10.6.4)</p> <p><strong>1.</strong> Open these files in the Property List Editor: <strong>/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX Product Types.xcspec</strong> and <strong>/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Specifications/iPhone Simulator ProductTypes.xcspec</strong></p> <p><strong>2.</strong> Locate the item in the “<strong>MacOSX Product Types.xcspec</strong>” that has the product type <code>com.apple.product-type.library.dynamic</code> and drag it to the “<strong>iPhone Simulator ProductTypes.xcspec</strong>”.</p> <p><img src="https://i.stack.imgur.com/YhIW5.png" alt="Xcode screenshot 1"></p> <p><strong>3.</strong> Open “<strong>MacOSX Package Types.xcspec</strong>” and “<strong>iPhone Simulator PackageTypes.xcspec</strong>” found at the same places.</p> <p><strong>4.</strong> Locate the item in the “<strong>MacOSX Product Types.xcspec</strong>” that has the package type <code>com.apple.package-type.mach-o-dylib</code> and drag it to the “<strong>iPhone Simulator PackageTypes.xcspec</strong>”.</p> <p><img src="https://i.stack.imgur.com/QQC6p.png" alt="Xcode screenshot 2"></p> <p><strong>5.</strong> Repeat the steps for the “<strong>iPhoneOS.platform</strong>” and relaunch Xcode if it was running.</p> <p>Now, lets build a dylib. Start out with the “<strong>Cocoa Touch Static Library</strong>” Templete. That should included the Foundation.framework in the project. Here are the changes I made on top of the templete to build dylib.</p> <p><strong>1.</strong> Open the file <em>project.pbxproj</em> (found inside the Xcode project file bundle) in a Text Editor. Search for string “<strong>producttype</strong>”, change it’s value to <code>com.apple.product-type.library.dynamic</code>;</p> <p>Now, open the project with Xcode, go to <strong>Project->Edit Project Settings</strong></p> <p><strong>2.</strong> “<strong>Installation Directory</strong>” set to <code>@executable_path/</code> because I plan to put the dylib in the same directory as the app’s executable.</p> <p><strong>3.</strong> “<strong>Mach-O Type</strong>” set to Dynamic Library</p> <p><strong>4.</strong> “<strong>Executable Extension</strong>” set to dylib</p> <p><strong>5.</strong> “<strong>Executable Prefix</strong>” set to empty</p> <p><strong>6.</strong> Add one or two simple methods to the library and build it.</p> <p>Now, create an app to test it. This time, I choose the <strong>View-based Application</strong>. Hook up a UIButton and a UILable to call the lib and showing return message. You can <a href="http://blog.iosplace.com/wp-content/uploads/2010/10/TestApp.zip" rel="noreferrer">download the complete project TestApp</a> and play with it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload