Hi -
I tried to fix this code and compile it for Phone Toggle but I don't have necessary setup to compile the code to create dylib and also I am absolutely noob at developing for iPhone.
So here is the code. I take no credit. This is from Bigboss site. There is one FAQ on how to create SBSettings toggle. Sample source code was given for the Location toggle.
I just changed some things and I don't know how to change others (see my comment at the bottom). Some developer can fix it and compile the dylib. I have put my comments.
File name is main.m.
-----------------------------------------------------------------------------
#import <UIKit/UIKit.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
// Determines if the device is capable of running on this platform. If your toggle is device specific like only for
// 3g you would check that here.
BOOL isCapable()
{
return YES;
}
// This runs when iPhone springboard resets. This is on boot or respring.
BOOL isEnabled()
{
NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile

"/var/mobile/Library/Preferences/com.apple.BTServer.airplane.plist"];
BOOL Location = [[plistDict objectForKey

"airplaneMode"] boolValue];//mytakeontech: please note we have to convert on/off to Boolean here. I don't know the syntax
return Location;
}
// This function is optional and should only be used if it is likely for the toggle to become out of sync
// with the state while the iPhone is running. It must be very fast or you will slow down the animated
// showing of the sbsettings window. Imagine 12 slow toggles trying to refresh tate on show.
BOOL getStateFast()
{
return isEnabled();
}
// Pass in state to set. YES for enable, NO to disable.
void setState(BOOL Enable)
{
NSMutableDictionary *plistDict = [NSMutableDictionary dictionaryWithContentsOfFile

"/var/mobile/Library/Preferences/com.apple.BTServer.airplane.plist"];
if (Enable == YES)
{
[plistDict setValue

"on" forKey

"airplaneMode"];
[plistDict writeToFile

"/var/mobile/Library/Preferences/com.apple.BTServer.airplane.plist" atomically: YES];
}
else if (Enable == NO)
{
[plistDict setValue

"off" forKey

"airplaneMode"];
[plistDict writeToFile

"/var/mobile/Library/Preferences/com.apple.BTServer.airplane.plist" atomically: YES];
}
// notify_post("com.apple.locationd/Prefs"); //mytakeonTech: I am not sure whether this is needed for Airplanemode
}
// Amount of time spinner should spin in seconds after the toggle is selected.
float getDelayTime()
{
return 0.6f;
}
// Runs when the dylib is loaded. Only useful for debug. Function can be omitted.
__attribute__((constructor))
static void toggle_initializer()
{
NSLog(@"Initializing LServices Toggle\n");
}
------------------------------------------------------------------------------------
Note: Please note that this code is not correct as of now. Location Toggle in .plist stores the value 1 or 0 for on and off but Airplane mode toggle .plist stores value on and off. I am not expert in this programming so I am not sure how to convert on off strings to Boolean 1 and 0 so some dev please fix my code (method BOOL isEnabled())and then please compile this into dylib and I hope we are done!
Again, this is just my assumption and I may be wrong, but I think the Phone toggle is broken because the .plist file for Phone toggle used to have values 1 or 0 but now they are changed to on or off. Can someone with iPhone OS 3.1.2 confirm this?
I hope someone comes forward!