How can I make a tweak that has multiple options to choose from with THEOS - tweak

So I was thinking of making a tweak for my iOS device and I wanted to make a settings patcher that had a few options for the user to choose from.
Example: Changing the color of the screen flash. If I wanted to have a range of colors for the user to choose how would I make the tweak.xm look?
%hook SBScreenFlash
- (void)flashColor:(id) {
//What would go here so that multiple options would show?
}
%end

If you want to make preferences for your tweak, you should think about making a PreferenceBundle using Theos (it's one of the built-in templates).
You can find documentation about it on iphonedevwiki. The PreferenceBundle will then write the user's settings to a file named com.yourname.yourprefbundle.plist located in /var/mobile/Library/Preferences/
Your tweak will have to read in this plist and do something accordingly

Related

How to check if any apps are associated with file extension

I want to make "Open in.." function in my iOS application.
Is there any way to check if any app on this device is associated with file extension that i want to share?
If there are no apps on current device to open file with such an extension than UIDocumentInteractionController will not be displayed after clicking on "Open in.." button, but i want not to show this button in such case.
So the question is: how to check if any app on device can open some file with specific extension?
Update:
For example UIDocumentInteractionController has NSArray property icons.
It contains images of all aplications that can open the file with my extension. But if there are no applications it contans image of empty application.
So i can't check it using docInteractionController.icons.count == 0 for example. I am looking for other tricks.'
Thanks, in advance.
Although UIDocumentInteractionController does not offer a way to discover in advance whether there are any applications that can handle a document, -presentOpenInMenuFromRect: will return a flag indicating whether there were any applications that could open a document. This requires you to have already set up and presented the controller, which is not optimal.
There is a workaround for this, a little hacky but is functional: Before you invoke the "real" interaction controller, create a dummy one using a dummy document, and present it from the rect of the window's bounds. This guarantees that it will "appear" offscreen, so your user won't see it. At that point, you have the flag returned from -present, and you can immediately dismiss the dummy controller, and the proceed to show your UI appropriately.
On OSX, you can get a list of application bundle identifiers capable of handling a specific content type using LSCopyAllRoleHandlersForContentType. But on iOS, I don't think there is such a way.
If I find, I'll edit my answer.
Considering you are looking for other tricks, you can check if that one image in the icons array is the generic document icon.
If it is then you know that there is no app associated to handle that file type. But this approach will be OS version dependent as generic file icon may change.
From the official documentation:
To declare its support for file types, your app must include the
CFBundleDocumentTypes key in its Info.plistproperty list file. (See
“Core Foundation Keys”.) The system adds this information to a
registry that other apps can access through a document interaction
controller.
To me this indicates that the registry can only be accessed through UIDocumentInteractionController and so no, you would not be able to know in advance if there are any available apps for the file format (which would be totally in line with Apple's philosophy of not letting apps interact directly with each other).
UPDATE:
as you said the icons property contains an image even with no applications present. I checked and all the other methods and properties of the controller do not give an hint about the apps that may open the current file format.
You said in case that no app can open the specified file format there is an "image of empty application". Maybe you can extract that icon and when the array icons only has one image check if the extracted image and the icon are the same?

iPhone application preferences

I've been doing some research and so far I've been unable to find out how to display a Settings.bundle inside an application. The guides that I found are:
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/Preferences/Preferences.html
http://blog.webscale.co.in/?p=274
http://knol.google.com/k/iphone-sdk-application-preferences#
These all seem to skip a step: How to display the plist from a view in your application. I've got my view set up and my plist file set up, but I have no idea how to display the preferences plist from the view. Do I manually load everything and put them into labels, switches and whatnot?
This may seem like a stupid question but I honestly don't know. Would anyone be able to explain this to me?
Thanks in advance
EDIT: To clarify; I've found out that this allows me to access the preferences through the settings app. However I want to access these through a tab in the app itself.
http://knol.google.com/k/iphone-sdk-application-preferences#Step_4(3A)_Retrieving_Values_of_Settings appears to describe exactly how to access these...
It's a one-liner so i'll paste it here:
NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:#"<Setting Key>"]
There's no magical setting key that you have to use. Use whatever you like, and it'll be there the next time the application loads.
I got the same problem; I have an application with a tabBarController as the RootController of my application and, separately, I have a settings menu (loaded from plist) available through the applications preferences of the device.
I do want to include this settings menu into my app as an other view for my tabBarController in order to avoid to have to exit my application to change the settings.
Finally, I have the plist file ready, I just want to know a way to do something like
[C#]
settingsController.View = UIView.LoadFromPList("settings.plist");
tabBarController.addController(settingsController);
... anybody knows ?

One App, Multiple Branding

I have made an application for the iPhone but it is required to be released with multiple brandings. Eg Differernt:
App Name
Icons
Default.png
Text replaced for the app name in IB
Colour schemes for all images such as backgrounds, icons etc
I'm not sure of the best way to do this.
I was thinking of a plist file for each branding that would have the name of the files to load eg "brand1_background.png" for brand1 but that would get very messy with the text replacement. It would also mean that all brands images would be in the package making it of larger size.
Looking around a bit I could have an 'images' folder for each brand and drag it in to build that brand's app, however the text is still an issue.
I'm wondering how everyone else would handle this situation as I want to do it as right as possible.
There are 2 different aspects to this problem, which I'd describe as follows:
Stuff that can be changed dynamically
Stuff that can't be changed dynamically
The first category is super easy. If you have your colo(u)r schemes stored in some easily-readable format like a plist or whatever, you can just load up that file during app startup, and build UIColor objects from them and use those where appropriate. The same goes for images used within the app itself. This is not a hard problem.
The second category is trickier. This is stuff that has to be baked into the application because of code signing. This means that the things like the App Name, the icon, Default.png, etc, all have to be changed before the app is signed in the compilation process. So what I'd do is bake up a bunch of scripts to take your branding information (name, image files, icons, etc) and load it up, then generate your Info.plist file and whatnot. This should be done as one of the first phases of your compilation.
For what it's worth, I work on an application where we do exactly this process, and it works pretty well. It's a bit tedious to update when we change what resources get branded, but I'm not sure there's any decent way around that.
Create a target for each of your brandings. For each single target you can add different files (e.g. images) and set an app name. You can even use the same file names (but stored under a different location) and you can build your brand-apps pretty fast.

In-app settings controlled by plist?

Is there a library or good tutorial which covers creating in-app settings, like this:
http://img.skitch.com/20090625-s8bf6ahybwe3cesd1id38h3nt.jpg
What I would like is if it:
doesn't use the built-in Settings app, and does not replicate it's settings in the Settings app
is controlled by a plist file with various Dictionaries and Arrays
creates a nice looking table view
allows edit-in-place text fields as well as switches and sliders and ticks etc
doesn't have any of the annoying problems I've come across when trying to build my own version (not scrolling to show the textfield, cells disappearing)
JUST TO EMPHASIZE: I DO NOT WANT THE SETTINGS TO APPEAR IN THE SETTINGS APP.
It would appear that the iphone dev world is crying out for such a thing.
THANK YOU!
InAppSettingsKit
I've used the open source project InAppSettings, and it works well.

How to Show a GPL licence in iphone application bundle

i am making an app for iphone and for that i am using certain free libraries.My problem is that i want to show their complete license of nearly 4-5 pages in my application bundle so that a user can open settings in iphone and see that licensing page at one time but i am unable to do it.I have read these Specifiers for making an application bundle .
PSGroupSpecifier
PSTitleValueSpecifier
PSTextFieldSpecifier
PSSliderSpecifier
PSToggleSwitchSpecifier
PSMultiValueSpecifier
PSChildPaneSpecifier
but i want to show a page full of text like Settings->General->About->Leagl
just like in iphone through PSChildPaneSpecifier .Please help me how to do this>???
Thanks
You can create the same effect as used by Apple's iWorks apps for the license > section of the settings, without using any custom preference controller. Note this works for iOS 5 on the iPad, I have not tried it elsewhere. Use a PSChildPaneSpecifier for the initial control in the root plist. This points to the name of another plist file which will be the displayed child pane. You do not add .plist to the name within the root.plist file, it is implied. This plist file must be within the settings bundle. Next, use PSGroupSpecifiers in the child pane as the controls. For each paragraph use another PSGroupSpecifier - so the thing will scroll. Only use the Title section of the PSGroupSpecifier. The next gotcha that I found, was that by putting the strings in the plist file, the text was clipped in portrait orientation, so a placeholder string needs to go in the plist file and a StringTable used to point to a strings file. Text read from the strings file is properly kerned and displays without clipping.
The iPhone's "Legal" page is a custom preference controller which you can't use (not even with undocumented methods – you need to write a preference bundle in system locations which AppStore apps can't reach at all).
If you'd like to display the license, show it in the app.
I think you are going to need to use something like a UITextView, just make it non-editable. You can make in unobtrusive in your app but I think that is the only way to have 4-5 pages.
I don't think there is a nice way of displaying this in the preferences bundle. Personally I would either provide a series of url links or bring the preferences into the app itself. There is a good framework on github here that you may be able to modify.