inside my class, It doesn't get called... Only when its inside the main appdelegate class..
How do you make it work inside any class?
Thanks
You don't. applicationDidEnterBackground is an app delegate method. The UIApplication object sends this message to the app delegate, and ONLY to the app delegate.
You could have your app delegate broadcast an NSNotification, and then any of your objects could listen for that notification. Something like this:
That will cause the object's enteredBackground: method to be called when the app enters the background. (It will crash if the object doesn't have a enteredBackground: method)
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
You don't. applicationDidEnterBackground is an app delegate method. The UIApplication object sends this message to the app delegate, and ONLY to the app delegate.
You could have your app delegate broadcast an NSNotification, and then any of your objects could listen for that notification. Something like this:
That will cause the object's enteredBackground: method to be called when the app enters the background. (It will crash if the object doesn't have a enteredBackground: method)
Amazing! I dont know why, but I never used notifications before.. it will, beside fixing this challenge, help me a lot in the future.
[quote=Duncan C;239328]You don't. applicationDidEnterBackground is an app delegate method. The UIApplication object sends this message to the app delegate, and ONLY to the app delegate.
You could have your app delegate broadcast an NSNotification, and then any of your objects could listen for that notification. Something like this:
You don't. applicationDidEnterBackground is an app delegate method. The UIApplication object sends this message to the app delegate, and ONLY to the app delegate.
You could have your app delegate broadcast an NSNotification, and then any of your objects could listen for that notification. Something like this:
------
Where do you place this code? in a method that I want to call?
Example I want the reloadData method to be called via the NSTimer, where would I place this NSNotification code?
Notifications and timers are two different things. The original poster was asking for a way for objects other than the app delegate to be notified when the app enters the background.
If you have questions about using timers you should start a new thread.
If you want other objects to be notified about applicationDidEnterBackground messages, the description above tells you exactly where to put it. The applicationDidEnterBackground method goes in the app delegate.
If you have another object, like a view controller, that you want to get a notice when the app gets a did enter background, you add 2 things to the object that you want to be notified:
1. Put the addObserver call (above) in that object's init method.
2. You then need to write an enteredBackground: method method with the following signature:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Notifications and timers are two different things. The original poster was asking for a way for objects other than the app delegate to be notified when the app enters the background.
If you have questions about using timers you should start a new thread.
If you want other objects to be notified about applicationDidEnterBackground messages, the description above tells you exactly where to put it. The applicationDidEnterBackground method goes in the app delegate.
If you have another object, like a view controller, that you want to get a notice when the app gets a did enter background, you add 2 things to the object that you want to be notified:
1. Put the addObserver call (above) in that object's init method.
2. You then need to write an enteredBackground: method method with the following signature:
Notifications and timers are two different things. The original poster was asking for a way for objects other than the app delegate to be notified when the app enters the background.
If you have questions about using timers you should start a new thread.
If you want other objects to be notified about applicationDidEnterBackground messages, the description above tells you exactly where to put it. The applicationDidEnterBackground method goes in the app delegate.
If you have another object, like a view controller, that you want to get a notice when the app gets a did enter background, you add 2 things to the object that you want to be notified:
1. Put the addObserver call (above) in that object's init method.
2. You then need to write an enteredBackground: method method with the following signature: