Coder Social home page Coder Social logo

kgn / inappsettings Goto Github PK

View Code? Open in Web Editor NEW
234.0 19.0 33.0 696 KB

InAppSettings provides a view controller that displays the application's Settings.bundle as it appears in the iPhone settings. Allowing the same preferences in app and in the iPhone settings.

License: MIT License

Ruby 1.07% Objective-C 98.93%

inappsettings's Introduction

InAppSettings

InAppSettings is an open source iPhone and iPod touch framework for displaying an in app version of the settings from the Settings.bundle.

There has been a lot of debate over whether an app's settings should be in the app or in the Settings app. InAppSettings is an open source framework determined to remedy this situation once and for all by easily allowing developers to have the same settings in the Settings app in in their app. InAppSettings uses the same Settings.bundle so there is no duplication of files or work. Simply add InAppSettings to the app's project and call it's view controler from code or Interface Builder and you're done! The InAppSettings wiki contains a full guide, including example code, for adding InAppSettings to an iPhone or iPod touch app.

By: David Keegan

With contributions from:

  • Shayne Sweeney
  • Hendrik Kueck
  • Peter Greis
  • Kurt Arnlund

Features

  • 100% re-implementation of the look and functionality of the Settings app.
  • Easily add InAppSettings to any navigation controller from code or Interface Builder, InAppSettings can also be displayed as a modal view.
  • Support for all versions of the iPhone and iPod Touch OS, 2.0+.
  • Support for settings language localization.
  • InAppSettings contains a class method for initializing all the user defaults in the Settings.bundle.
  • InAppSettings adds additional functionality to the Settings.bundle by adding optional values for in app titles and opening urls.
  • Sample project that demonstrates how to use InAppSettings from code, Interface Builder and a modal view.

License

InAppSettings was developed by David Keegan and is distributed under the MIT license so it can be used in free or commercial apps. See the LICENSE file for more information.

How to add InAppSettings to Your App

Drag InAppSettings into your project in Xcode. Make sure the dialog looks like this, then press 'Add'.

If you will be using InAppSettings in multiple projects, and I hope you do:), add InAppSettings to your source trees in the Xcode preferences. If you do this the 'add' settings should look like this, then press 'Add'.

InAppSettingsViewController

The InAppSettingsViewController is a subclass of the UIViewController that displays the settings from the Settings.bundle. It can be used from code and Interface Builder.

Using InAppSettingsViewController From Code

#import "InAppSettings.h"

- (IBAction)showSettings{
    InAppSettingsViewController *settings = [[InAppSettingsViewController alloc] init];
    [self.navigationController pushViewController:settings animated:YES];
    [settings release];
}

Using InAppSettingsViewController From Interface Builder

To use InAppSettingsViewController in Interface Builder, change the class type of any UIViewController to InAppSettingsViewController.

To work correctly the InAppSettingsViewController must be added to an existing UINavigationController.

InAppSettingsTestApp demonstrates how to use InAppSettingsViewController from code and Interface Builder.

InAppSettingsModalViewController

The InAppSettingsModalViewController is a subclass of UIViewController that creates its own UINavigationController. It is designed to be used as a modal view and is created with a 'Done' button that will dismiss the view.

How to use InAppSettingsModalViewController from code

#import "InAppSettings.h"

- (IBAction)presentSettings{
    InAppSettingsModalViewController *settings = [[InAppSettingsModalViewController alloc] init];
    [self presentModalViewController:settings animated:YES];
    [settings release];
}

The InAppSettingsModalViewController should not be used from Interface Builder.

InAppSettingsTestApp demonstrates how to use InAppSettingsModalViewController as a modal view.

[InAppSettings registerDefaults]

The user defaults from the Settings.bundle are not initialized on startup, and are only initialized when viewed in the Settings App. InAppSettings has a registerDefaults class method that can be called to initialize all of the user defaults from the Settings.bundle.

How to use [InAppSettings registerDefaults] from code

The InAppSettings registerDefaults method should be called from the AppDelegate's initialize method.

#import "InAppSettings.h"

+ (void)initialize{
    if([self class] == [AppDelegate class]){
        [InAppSettings registerDefaults];
    }
}

The name of the 'AppDelegate' will need to change to the name of the app's AppDelegate class.

Custom settings specifier keys

InAppTitle

InAppTitle is an optional settings specifier key that can be added to any settings specifier. If present this title will be used in InAppSettings.

<dict>
    <key>Type</key>
    <string>PSGroupSpecifier</string>
    <key>Title</key>
    <string>Change the theme of the app</string>
    <key>InAppTitle</key>
    <string>Change the theme of the app, these changes will take effect the next time the app is launched</string>
</dict>

The Settings app will display: "Change the theme of the app", but InAppSettings will display: "Change the theme of the app, these changes will take effect the next time the app is launched".

InAppURL

InAppTitle is an optional settings specifier key that can be added to PSTitleValueSpecifier. If present a disclosure indicator will be added to the cell, and the specified url will be opened when the cell is tapped.

<dict>
    <key>Type</key>
    <string>PSTitleValueSpecifier</string>
    <key>Title</key>
    <string>Created by:</string>
    <key>Key</key>
    <string>testUrl</string>
    <key>DefaultValue</key>
    <string>kgn {+}</string>
    <key>InAppURL</key>
    <string>http://www.kgn.com</string>
</dict>

To open a webpage the url MUST startwith "http://".

InAppSettingsTestApp

The InAppSettingsTestApp is a Xcode project for testing InAppSettings. It also demonstrates all the ways to use the InAppSettings view controllers and class methods.

inappsettings's People

Contributors

keegan3d avatar kgn avatar koke avatar littleorangec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inappsettings's Issues

Dynamically add specifiers

Support the ability to add new items on the fly, eg. apple seetings for adding new mail accounts, or the 'wi-fi netwroks'->choose a network.

PSTitleValueSpecifier title

If there is no title on a PSTitleValueSpecifier the default value becomes the title, this is currently not the case in InAppSettings.

Make keyboard dismissable

When the keyboard pops up, it covers my tab bar. To make it dismissable I have added the following:
PSTextFieldSpecifierCell.m In setupCell add: self.textField.delegate = self; self.textField.returnKeyType = UIReturnKeyDone;
Beneath that add the method: - (BOOL)textFieldShouldReturn:(UITextField *) theTextField { [theTextField resignFirstResponder]; return YES; }
Change the interface in the .h file to: @interface PSTextFieldSpecifierCell : InAppSettingsTableCell {
I don't know if this is entirely correct, but it works for me.
cheers P

scroll to text cell in 2.0

In iPhone 2.0 the text fields cell scrolls to the middle of the table at its original height, not the middle of the table with the keyboard insets.

Remove keyboard notification observer

In -dealloc and -viewDidUnload in InAppSettingsViewController, -[NSNotificationCenter removeObserver:] should be called:
@implementation InAppSettingsViewController

...

- (void)viewDidUnload {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super viewDidUnload];
}

...

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    ...
    [super dealloc];
}

...

@end

Custom Function Triggers

I know it would ONLY work within the app and not in the actual settings page, but it would be great to have a button under a text field that would look something up from the Internet. It would trigger a function and then listen for a completion trigger, all the while, showing a "busy" interface.
For example: I have a tax rate text field in my settings. It would be awesome for me to be able to let the user tap a button, use the iPhone's GPS to locate them, then look up the local sales tax for wherever they're at, and then auto-input the preference for them.
This setting would not be in the main Settings.app listing, but would be a great enhancement to allow the users a better experience within the app.
Any thoughts?

Reload if a setting is changed in the settings app while in background

If the in app settings controller is visible, if you leave the app and go to the Settings app and change a setting, when you come back to the app the settings controller still has the old values. Fix with these changes:

  • (void)viewWillAppear:(BOOL)animated {
    ...
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
    }
  • (void)viewWillDisappear:(BOOL)animated{
    ...
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
    }
    -(void)applicationWillEnterForeground:(NSNotification*)notify{
    // reload in settings in case they were changed in the prefs app.
    [[NSUserDefaults standardUserDefaults] synchronize];
    // show any changes if they happened in the background.
    [self.tableView reloadData];
    }

iOS7 Issue with the Slider setting

In InAppSettingsPSSliderSpecifierCell.m

It appears

- (void)slideAction

is not being called when the deployment target is iOS7. I suspect it's something with the

[self.valueSlider addTarget:self action:@selector(slideAction) forControlEvents:UIControlEventTouchUpInside+UIControlEventTouchUpOutside];

line but I am still researching.

navigationController nil when pushing multi-value VC

I'm using InAppSettings within a tabbar. When the view is pushed in didSelectRowAtIndexPath the navigationController is nil.
How can this be used in this context? (BTW.. is there a better forum to post questions?)

Color of header title

Hello, I have used inAppSettings in my App and I have changed the background of the tableview. The problem I have now is that I can't see correctly the titles of groups because the default color is grey. I would like to change it to white.

¿How can I do that?

Thanks

Allow customization of fonts, text size, etc

It would be really nice to allow customization of all the options that are in InAppSettingsConstants.h so that the UI can be customized to fit a certain app's UI scheme.

Note: I am a rather new Objective-C/Swift developer, so I don't know exactly the extent of refactoring that this will take to implement. I am going to dig into the source code to figure out what's happening, and see if I can submit a pull request with the changes. Wish me luck 😄

Hide some settings unless a toggle value is enabled

Hi, I want to hide some settings unless a toggle value is set to YES. By default the toggle value will be NO and when changed to YES, it should show another table view cells where more settings can be added on the same page.. Please help.. Very URGENT.
Thanks.

Changes don't save and table doesn't scroll

So far, I'm impressed, the settings look like they should.
But when changing values, they don't get saved.
Also when selecting a row at the buttom of the screen, the table doesn't scroll, so I can't see what I'm editing.

Add help field

It will be nice if you add support for help field (InAppHelp for example). If the field is present, you could display info icon (i), and use popover feature from iPhone OS 3.2. I think it's easy to implements popover feature in iphone OS 2.0 to 3.1.3.

missing delegate for modal view controller

I'm missing a delegate in the modal view controller for willDismiss.
I'm using the modalViewController to display the settings when the app is started for the first time. The user than has to define a user name and password to logon to the server. After that, I'd like to continue in my app an logon to the server.
Therefore I need a delegate, that tells me, that the modelViewController will dismiss.

Extra functionality to show/hide preference

Greetings
In my application (LiveTrack 24 for iOS), I have recently added an option for the Live Map to pivot and follow the compass setting. All fine and well. What would be nice is to add an extra node to the xml, which would read a BOOL NSUserDefaults setting. As an example:
Before setting up InAppSettings, I would set the NSUserDefaults key "shouldShowMapPivot" based on whether or not the device has a compass built in. While parsing the plist, InAppSettings would then hide this settings entry if "NO", and show it if "YES".
The only other way that I can handle this is to make multiple plists, but then things start getting messy....
Thoughts ?
regards
Peter

A few leaks found

First, a big thanks for this code!!
After running my app through Instruments, I found a few leaks. Below is the info I extracted from Instruments. Let me know if you need anything else.
LEAKED OBJECT: Malloc 16 bytes EVENT TYPE: Malloc RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults loadFile]

  • (void)loadFile:(NSString *)file{ if the file is not in the files list we havn't read it yet NSInteger fileIndex = [self.files indexOfObject:file]; if(fileIndex == NSNotFound){ [self.files addObject:file];
    load plist NSDictionary *settingsDictionary = [[NSDictionary alloc] initWithContentsOfFile:InAppSettingsFullPlistPath(file)]; NSArray *preferenceSpecifiers = [settingsDictionary objectForKey:InAppSettingsPreferenceSpecifiers]; NSString *stringsTable = [settingsDictionary objectForKey:InAppSettingsStringsTable];
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for(NSDictionary *eachSetting in preferenceSpecifiers){ InAppSettingsSpecifier *setting = [[InAppSettingsSpecifier alloc] initWithDictionary:eachSetting andStringsTable:stringsTable]; if([setting isValid]){ if([setting isType:InAppSettingsPSChildPaneSpecifier]){ [self loadFile:[setting valueForKey:InAppSettingsSpecifierFile]]; }else if([setting hasKey]){ if([setting valueForKey:InAppSettingsSpecifierDefaultValue]){ [self.values setObject:[setting valueForKey:InAppSettingsSpecifierDefaultValue] forKey:[setting getKey]]; } } } [setting release]; } [pool drain]; [settingsDictionary release]; } }
    LEAKED OBJECT: NSCFDictionary EVENT TYPE: Malloc RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults init]
  • (id)init{ self = [super init]; if (self != nil) { self.files = [[NSMutableArray alloc] init]; self.values = [[NSMutableDictionary alloc] init]; [self loadFile:InAppSettingsRootFile]; [[NSUserDefaults standardUserDefaults] registerDefaults:self.values]; } return self; }
    LEAKED OBJECT: NSCFDictionary EVENT TYPE: CFRetain RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults setValues]
    NO CODE HIGHLIGHTED FOR THIS ONE AND I DIDN'T EVEN SEE THIS METHOD **
    LEAKED OBJECT: NSCFDictionary EVENT TYPE: CFRelease RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults dealloc]
    NO CODE HIGHLIGHTED FOR THIS ONE **
    LEAKED OBJECT: NSArrayM EVENT TYPE: Malloc RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults init]
  • (id)init{ self = [super init]; if (self != nil) { self.files = [[NSMutableArray alloc] init]; self.values = [[NSMutableDictionary alloc] init]; [self loadFile:InAppSettingsRootFile]; [[NSUserDefaults standardUserDefaults] registerDefaults:self.values]; } return self; }
    LEAKED OBJECT: NSArrayM EVENT TYPE: Retain RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults setValues]
    NO CODE HIGHLIGHTED FOR THIS ONE AND I DIDN'T EVEN SEE THIS METHOD **
    LEAKED OBJECT: NSArrayM EVENT TYPE: Release RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults dealloc]
    NO CODE HIGHLIGHTED FOR THIS ONE **

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.