Question

Is there an elegant way (Objective C or C) for my app (jailbroken iOS) to check whether a specific dynamic library is available or not in iOS, other than checking if the actual dylib file exists at a specific path with an NSFileManager or calling dlopen? (e.g., an object that has info about available dynamic libraries that I can access.)

Update: I know I can also make it a requirement in my project settings (Xcode), but then the app just crashes on startup if the dylib isn't available, without any feedback (if there's a way to catch this and do an alert before crashing, that would be an acceptable solution, too).

Was it helpful?

Solution

If you are using weak linking for your dylib, it should be pretty easy to detect if the library is present by checking for a particular symbol.

Say you have a void foo( void ); function in that library.

You can declare that prototype as extern in your own code, and use the weak_import attribute:

extern void foo( void ) __attribute__( ( weak_import ) );

This way, if the symbol is not found (because its not anymore in the library, or because the whole library is not available), the linker will set the address of the symbol to NULL.

You can then simply and elegantly check for that symbol:

if( foo == NULL )
{
    /* Alerts the user */
}
else
{
    /* It's safe to use foo() */
}

For further reading: Framework Programming Guide

OTHER TIPS

It's my personal opinion that your approach is off. When installing a jailbroken app, most end-users will install it through Cydia/Installer/Icy, which is a wrapper for APT.

When you do finally push your package up to those stores, you can specify package 'dependencies', which will make it so that your app will not be able to be installed at all, let alone be run, without those packages installed.

It's up to you, however, to determine the package which contains the dylib you wish.

There are only a few edge-case scenarios which could cause a missing dylib once installed from APT, namely deleting the libraries, messing with MobileSubstrate settings, and someone downloading your app outside of APT.

However, in this case, the users shouldn't expect your app to work perfectly, seeing as they have been messing around with developer-type things which they probably shouldn't be.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top