After exiting app, how to go back to the exact same screen where I left off? - objective-c

Is there a quick and easy way to have the app go back to the same screen after I put it in background mode?
I know there are frameworks just for this stuff, but has anyone done it without much sweat?
Thanks

In your app delegate, add a line to the applicationDidenterBackground: method that stores the current page via NSUserDefaults.
Then in the applicationWillEnterForeground: method, load up that saved value and restore the page.

Multitasking should enable this, while a device has enough memory to keep your app open. Otherwise how about using NSUserDefaults to store a string reference to your view?

As of iOS 5.1, there is no quick and easy way.

Related

How should I go about stopping/resuming all sounds within my iOS game?

I currently have background music that starts up when the app opens and runs an infinite loop until the user goes into the settings and turns the music off using this
-(IBAction)stopMusicButton{
[(AppDelegate*)[UIApplication sharedApplication].delegate stopMusic];
}
They can also resume the music in the settings page. What I'm a confused about is how to stop the other sounds in my app from playing if the user doesn't want the noise. For example, when the user navigates the menu of my app there are various sounds that play when certain things are pressed. How can I allow the user to be able to toggle these sounds on and off? There are also a few different views with their respective .h/.m files, all of which play sounds. If you could point me in the right direction I'd really appreciate it! Thanks in advance!
I use a singleton class to store settings information - you could probably use your app delegate as well. All you need is a boolean property called isSoundMuted or something like that. Set that whenever the sound is muted or unmuted, then check the variable's value before playing any sounds in an if block.
if (MySingletonClass.isSoundMuted == NO)
{
[self playSound]
}

iOS - Asynchronous Image Downloading

I am writing an app which is going to be displaying images found on my server in a UIImageView.
I need something that will asynchronously download the image and cache it while putting it in the UIImageView.
The download also needs to be able to be cancelled when I press a button.
Can anyone point me in the direction of something that can do this?
In the old times the framework for that was ASIHTTPRequest but is an abandoned project now. This https://github.com/AFNetworking/AFNetworking seems to be popular now.
Use the performSelectorInBackground:withObject: - method from NSObject ;)
Advise: The updating of the view must run on the main thread!
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html

What method gets called before a WebView is closed by owner window?

I'm working with a webview within a window of a Cocoa application. I would like to retrieve some values using stringByEvaluatingJavaScriptFromString on the webview and save them before the application shuts down. I tried using the applicationWillTerminate but by the time I reach this method, it is too late. I was wondering if there's something built into webview that I've missed or if anyone has an elegant solution to share.
If you want to save this information, why are you waiting until the app is about to terminate?

Problem: restarting App

My App is a view-based application. At the beginning I show my logo and after a delay of a few seconds it changes into another view. from then on the user can switch to a lot of different views.
Sooooo.. My Problem: The thing is, when I restart my App. [..well closing and reopen by touching the icon..] the app itself doesnt restart in the sence of jumping to the very first view. to the contrary: at restart the user just returns to the last view that was open.
So I dont know why this is.
Is it normal to somehow manually tell the app to return to the very first view after restart? And if so, how do I have to do that?
PS.
I have so no idea what to do.. Maybe my problem has to do with the timer i used in the first view to change after a delay of time?
Please, is there anyone, who can help me?
Your problem is that, as of iPhone 4, returning to the home screen does not terminate your app. It's just made inactive, so opening it again reactivates it. In most cases, this is a good thing. If it doesn't work for your app, you can add the UIApplicationExitsOnSuspend key to your Info.plist with a value of YES.
(As I said, you should only do this if it really helps usability. If it's just about getting your splash screen shown again, most users and possibly Apple will frown upon it.)
iOS 4.0 and greater have a fast-start thing that allows apps to restart back from where they were upon restarting. There are several ways to deal with this:
1.) your App Delegate receives info about being but into the background and resumed. - (void)applicationDidBecomeActive:(UIApplication *)application and - (void)applicationDidEnterBackground:(UIApplication *)application are the relevant functions here. Check the docs.
2.) You can also disable the background, inactive state completely by including UIApplicationExitsOnSuspend in you Info.plist as Chuck already pointed out.
Overall, you should check the application state docs on Apple's Side.

How can I force invalidation of a running Cocoa program without additional custom code?

I have multiple custom NSViews in my Cocoa program. I am looking for a way to force them to invalidate without having to add additional code while the program is running. If I were doing this with on Windows with the .NET framework, I would just drag part of my program offscreen and drag back on again. Areas that was offscreen get invalidated when they come back on screen. I haven't figure out how to do this with Cocoa - OSX.
The methods setNeedsDisplay should do it:
- (void)setNeedsDisplay:(BOOL)flag
- (void)setNeedsDisplayInRect:(NSRect)invalidRect
Docs here
Windows on Mac OS X are buffered by the Window Server and can't be forced to redraw by moving them around the screen. The only way the user can force a redraw is to resize the window.
Why do you need to do this, though?
Minimize the window and unminimize it. That happens to force a redraw.
I recommend you try F-script http://www.fscript.org/. It allows you to call methods on Cocoa objects while your program is running.
You could use it to call the setNeedsDisplay:(BOOL)flag or setNeedsDisplayInRect:(NSRect)invalidRect methods directly on the view you would like to invalidate.