iOS9 iOS9 iOS9 iOS9 iOS9 iOS9 iOS9 iOS9

Selecciona idioma

Spanish English

Adding preferences tutorial

by OlyDJ

Do you want to be a iOS deveolper? It´s really easy to start if you follow this tutorials. Today we gonna create a preferences panel for our first tweak project.

Adding preferences panel

    Hey! What if we don´t want our tweak to be enabled by some reason? This gonna be awesome, but there are lot of things we are going to do... So patience... You can mail me for questions or requests...

    Keep in mind that name and package´s name must be exactly as I wrote in this tutorial to work. I don´t wanna go deep on this, but it needs to be explained. iOS system takes the BundleID (bundle identifier) to read, write and interact with an app, tweak, etc... So if we named a tweak "com.android.funny", you must change every line that has "com.oly.firsttweak" to "com.android.funny".

    • 01- Open up MobileTerminal and enter "su" and password. We are going to make a backup of our tweak folder, so if something is going wrong or whatever we can go back to a "stable" release. Type "cp /var/mobile/firsttweak /var/mobile/firsttweak.backup01" and hit Enter (I knooow, we can do this with iFile/Filza quickly... But this way you´re learning something really useful. Mac OS and Linux have similar (even iquals) commands... so up to you!). And go inside our tweak folder (remember: "cd /var/mobile/firsttweak")

    • 02- Type "/var/theos/bin/nic.pl" to invoque theos and select "preference_bundle" (for me is option 5)

    • 03- Now type the name for your preferences tweak (Think that we are creating a project inside our tweak project). By example "FirstTweakPrefs"

    • 04- Next it asks for Package name (as in tutorial 2, type it in minus). So we type "com.oly.firsttweakprefs" and Enter.

    ATENTION!!! I have moved my firsttweak root folder to "/var/samba/Storage" for some reasons (that will be explained on another tutorial). So follow the path to files I´m writing, not the images one...

    • 05- If we take a look the contents of our tweak root folder, we have a folder named as "firsttweakprefs". Our preferences panel is created and linked to our tweak.
    • 06- Open up iFile/Filza and go to our "prefs" folder ("/var/mobile/firsttweak/firsttweakprefs"). We have 3 files and two folders ("theos" folderis a link, not a folder).
    • 07- First of all (again, we have created another project) open "Makefile" file (it has no extension, so iFile/Filza prompts how to open it), select "TextEditor".

    • 08- We must add a couple lines here. At the beginning of the document (those two lines are the same as tutorial 2), we type:

    TARGET = iphone:clang

    ARCHS = armv7 arm64 armv7s

    REMEMBER! This is for every projects. Make sure to do this everytime you want to create something.

    • 09- Save, close file and go inside "Resources" folder (here there are the plist files of our preference panel). Open "FirstTweakPrefs.plist" (do it with TextEditor).

    This is the original content:


    Don´t be afraid by this... It´s really simple... Plist files are the settings itself. We can add switches, sliders, etc... It´s structure is "key-value", so we assign a name for "key" (which will be called from our tweak preferences), and it´s "value".

    First 2 lines (Red and blue boxes) are for file identification. (Don´t touch that)

    The 3rd line tells iOS that this is a "Plist" file.

    4th line is a "Dictionary" which contains the items of our plist file.

    5th line it´s a "key" that indicates that next lines are the items of Dictionary.

    The next line is the array of items that will be readed.

    This can be confusing... a dictionary can contain objects, and dictionaries are objects (like an array, or a key). So next we have another Dictionary (which, in this particulary case, contains a group).

    Now we have a "key" named "cell" with a "string" value: "PSGroupCell". This is basically a group, that has a label at top with text "FirstTweakPrefs First Page"

    Now change that "string" text to "FirstTweak Preferences"

    The next line is the "close" for group Dictionary (So we tell iOS that we ended with that group).

    Now we have another Dictionary. We must change some things here, so try to change that Switch to be disabled by default, that the defaults name will be "com.oly.firsttweak", named "enabled" and with the visible label "Enable".

    Then we have the "close" for our switch and the "close" for our array.

    Next is the Title showed at the top in the middle. So change it to "FirstTweak Settings".

    Finally we have the "close" for the "root" dictionary, and the "close" for our plist.

    This is the changed file (adding that "PostNotification" key and value):

    • 10- Save the file, close it, and go back to our root directory. Open tweak.xm and add at the top:

    #define prefPath @"/User/Library/Preferences/com.oly.firsttweak.plist"

    static NSMutableDictionary *prefs;

    void refreshPrefs() {

    if(kCFCoreFoundationVersionNumber > 900.00) {

    [prefs release];

    CFStringRef appID2 = CFSTR("com.oly.firsttweak");

    CFArrayRef keyList = CFPreferencesCopyKeyList(appID2, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);

    if(keyList) {

    prefs = (NSMutableDictionary *)CFPreferencesCopyMultiple(keyList, appID2, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);


    } else {

    prefs = nil;


    } else {

    [prefs release];

    prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:[prefPath stringByExpandingTildeInPath]];



    static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {



    • 11- Now scroll down and find the first line "return FALSE;". Replace that line with this 3 (do it for both "methods"):

    if(prefs != nil && ([prefs count] != 0) && [[prefs objectForKey:@"enabled"] boolValue]) {

    return FALSE;

    } return %orig;

    • 12- Scroll down and type in the bottom of file:

    %ctor {

    @autoreleasepool {

    prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:[prefPath stringByExpandingTildeInPath]];

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR("com.oly.firsttweak.prefschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);




    It should look like this:


    All this will be explained in next tutorial. Basically we define a string that is our preferences iOS file. Then We create a Dictionary named "prefs". Next we use CoreFoundation Framework to write the user preferences for our bundle (that is the "prefs" Dictionary). Then we created something like an "action" (It will be activated with the "ctor" or "Constructor" line).

    We add a condition ("if" statement) to our methods, so there will active only when the switch is "enabled" (and if it is disabled return the original value). Finally we have the notification receiver (when you switch to "on", this receiver activates the "refreshPrefs" action, so it writes that the switch was changed on the preference file)

    • 13- Save the file, close it and delete the two "temporal" folders Theos created during first compilation, that folders are named: "_" and "objc". Go back to MobileTerminal (remember that you already has logged with root and you are inside our root project folder), type "make package messages=yes" and hit Enter.

    We are compiling our tweak again, you will see how theos do the magic. If all is OK then you can go with iFile/Filza to our "debs" folder inside our project.


    Just install it and check preferences. Test it (remember that this method requires a Respring).

Next tutorial: We gonna change "Slide to unlock" text to custom text.