How to detect application préference changes - iphone

I created a Settings.bundle in my app where the user can change some properties like font size. It works.
But when I leave my App, and I change my setting, I don't know how I can get notified of the change.
For the moment, I create a function call each time a view is loaded that check for app settings.
But I wonder if there is an other and proper way to do this.

You should use your app delegate's application:didFinishLaunchingWithOptions:, or an equivalent location, to check your NSUserDefaults values, or just read them in a UIViewController viewDidLoad method.
While there is no multi-tasking, this is more than adequate. On MacOS X Cocoa we use KVO and bindings to check for changes during the execution of an application; no doubt something similar will work for 4.0 if required.

I finally found the solution. Like you said Paul, for 4.0 sdk version, there is something similar and I found it in "UIApplicationDelegate protocol".
Thank you for helping me. ;)

Related

App Created with ios4 is crashing in ios6 and not installing

My App, which is created for iOS4, is crashing in iOS6 and is not installing on simulator or device.
It just shows the splash screen and crashes.
Did finish Launching is not being called.
Can anybody please Help?
Finally i got the solution of my problem mentioned above.
In my ios4 App, in FirstViewController.xib "Use AutoLayout" was checked.
I just removed the checkmark and my App start working.
Amazing!!!
I would recommend creating a new project, and either carefully looking for the changes in delegate or any deprecated code, or just moving all of your code to the new project. Also, you should run a convert to modern syntax check.
There may be issue with Application Delegate. The obvious reason - your object is not set as an application delegate.
Looking at Apple documentation there is quite a few ways to accomplish it:
Remove application delegate binding in Interface Builder (.xib file
for the window) Set 4th parameter of UIApplicationMain in main.h to
something else than nil.
Check you nib file in Interface Builder and see if the App Delegate is setup.
Or Reference to documentation Core Application Design
Hope this will you out.
Look into the release notes of xcode, ios6
It is said that when working with IOS6, Auto Layout is turned on and that crashes the app if used on older versions. Check the link, which has other things to watch out for:
https://developer.apple.com/library/mac/#releasenotes/DeveloperTools/RN-Xcode/_index.html
https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

xcode not creating different app Delegate for universal app

i am totally new to iphone and i am trying to create a universal app.
Now I am creating an empty application. According to all tutorials , by checking universal option it should auto create appdelegates for both iphone and ipad.
But all i can see is only one appdelegate . Kindly tell me how can i create both.
Best Regards
Brayden is correct in answering that you almost never need multiple app delegates. All the delegate usually does is handle the moments when the application launches, suspends or terminates. Back in the days when iPhones ran iOS 4.0, and iPads ran iOS 3.2, you might need very different code in the delegate because only iOS 4.0 supported multitasking. Those days are long gone, and your delegate should probably act the same on all devices.
Yes, you sometimes do reach a point where your program must behave differently on iPhone and iPad. Check the idiom at that time and no earlier. Otherwise you're just duplicating code to no purpose.
My most recent app contains almost no special checks for iPhone or iPad. It doesn't even use different XIBs. Instead, my custom views implement layoutSubviews to fill the space available.
That said, once you understand app delegates, maybe you will find a situation where you need them to be different. If you are absolutely certain that your iPhone and iPad behavior will be so wildly divergent, you will need to:
Manually create a new class (preferably inheriting from the existing AppDelegate class)
In your main.m, send the class name of your new delegate to UIApplicationMain depending on the idiom.
See this answer to "Can I create App Delegate file in my project?" to see the changes to main.m.
You really should only be using one AppDelegate for a Universal application. You can use this to share common things that you'll do in there. What exactly do you need multiple AppDelegates for? If you need to do something specific to a device type (i.e. - iPhone or iPad) then you can do a ternary expression like below:
(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? NSLog(#"iPad") : NSLog(#"iPhone");

How can I use a UIPickerView in my settings.bundle like how the 'nike+ ipod' app does it?

I can't see how this is possible from the documentation but here nike is doing it in their app so there must be a way.
It's impossible unfortunately. Apple developed it for Nike, so they used tricks of their own to do it. It might actually be possible, but it's certainly undocumented if possible. Impossible for an App Store app. Let us know if you figure out a way to do it even if it's undocumented.
If you use the library InAppSettingsKit, you can have a setting that uses a custom subview (a custom UIViewController) to display the choice to the user. So all you have to do is to create a custom view controller that looks just the one in your picture (it's basically just a UITableView and a UIPickerView).
In the example app that comes along with InAppSettingsKit, there is an example on how to use a custom subview.

UITransitionView, UIAlertSheet

I'm trying to update an iOS open-source project that has been abandoned in 2008. I've found some references to UITransitionView and UIAlertSheet in the code, but I can't find any documentation on Apple dev center about that. Are they simply deprecated?
Thanks !
They are both internal views used by Apple and not published in the SDK.
It's difficult to say exactly what Apple will or won't do however, adding a view to an undocumented view you retrieve from a superView message is not contentious. What you should not do (or be careful if you do do) is make assumptions about the view you are adding to. Specifically its class but even basic things like the fact that it even exists.
What are you trying to do? There may be a simpler way - like adding your view directly to the app's UIWindow.
UITransitionView and UILayoutContainerView
UIAlertSheet Class Reference
UITransitionView is internal apple framework and not published in SDK..See this thread
UIAlertSheet I never heard about..:(

iPhone SDK 4.0: Testing if view is displayed

using iPhone SDK 4.0, how does one determine if a UIViewController is currently in the viewDidAppear state (currently visible). I could set a flag but was wondering if there is a better way.
Thanks.
Nope, setting a flag is the best way, as you never know if something is in front of it.
Have fun!