views:

54

answers:

1

Is there anyway to save a URL with NSUserDefaults without setURL:forKey: that is only available to iOS 4.0 and later?

I am loading HTML files locally with fileURLWithPath, and it starts at an intro page and the user can click through to whatever. For now, everytime a user starts over it loads back default to intro.htm. I would like to be able to save their current page to NSUserDefaults on viewdiddissapear and reload it next time, but can't find any solutions besides setURL:forKey:. Anyone out there know a solution?

+1  A: 

You can turn the URL into a string:

[[NSUserDefaults standardUserDefaults]
 setObject:[url absoluteString] forKey:@"url"];

And vice versa:

NSURL *url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults]
                                   objectForKey:@"url"]];
Daniel Dickison
Thanks. Exactly what I wanted! Wondering if you know of a way to create a back-forward URL list? I have a button that calls javascript history.go(-1) to return user to an index. Now that I have this feature which opens directly to the last loaded page, that button no longer sends them to the index because pressing Back does nothing. I tried doing a double URL call to the main index and then the saved page but that still didnt load the index into the "back" history..
ElChico