Libhide

From iPhone Development Wiki
Revision as of 22:19, 26 April 2014 by SharedRoutine (talk | contribs) (fixed header and function call)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Libhide
Cydia Package
Developer BigBoss
Package ID libhide
Latest Version 2.4.1-1


libhide is a library that allows you to hide / unhide icons on SpringBoard. For example, if your extension has a Preference Bundle (which is accessible from the Settings app), you can use libhide to give your users the option of showing or hiding an icon on SpringBoard as an easy way to access those preferences.

libhide works on iOS 6 and 7, and possibly to as early as iPhoneOS 2.

Dynamic Loader

In order to load the library and to execute its functions, you can use the implementations of the dynamic linking loader: dlopen(), dlsym(), dlclose() and dlerror().

  • dlerror() returns a human readable error message of an error for dlopen and dlsym or NULL if there is no error.
  • dlopen() loads the dynamic library using the null terminated path given as the parameter. The second parameter expects a flag on how to load the library.
  • dlsym() takes a 'handle' returned by dlopen and a symbol name to lookup. It returns either the address of the symbol or NULL if it was not found.

Example code

We first declare our static functions which will initialize from the dynamic library:

#import <dlfcn.h>

static void *libhide;
static BOOL (*IsIconHiddenForDisplayID)(NSString *displayID); //a method to determine if the icon is already hidden or not
static BOOL (*HideIconViaDisplayID)(NSString *displayID); //hides the icon for the display identifier
static BOOL (*UnHideIconViaDisplayID)(NSString *displayID); //unhides the icon
static NSString *appDisplayID = @"com.yourcompany.appdisplayid"; //our bundle identifier

Next we will initialize our functions so we are able to call them.

libhide = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);

The flag RTLD_LAZY performs lazy binding, which means it only resolves symbols as the code that references them is executed. If the symbol is never referenced, it is never resolved. Lazy binding is only performed for functions; variables are bound when the library is loaded.

IsIconHiddenForDisplayID = reinterpret_cast<BOOL (*)(NSString *)>
                                                     (dlsym(libhide,"IsIconHiddenDisplayId"));
HideIconViaDisplayID = reinterpret_cast<BOOL (*)(NSString *)>
                                                     (dlsym(libhide,"HideIconViaDisplayId"));
UnHideIconViaDisplayID = reinterpret_cast<BOOL (*)(NSString *)>
                                                     (dlsym(libhide,"UnHideIconViaDisplayId"));

Now we are able to call those three functions as normal functions. Like so:

if (IsIconHiddenForDisplayID(appDisplayID)) {
       UnHideIconViaDisplayID(appDisplayID);
} else {
      HideIconViaDisplayID(appDisplayID);
}

More examples: Circuitous has a good example of just hiding and unhiding a icon, and the official sample code shows some of the other things libhide can do.

External links