iPhone - 没有setURL保存URL:forKey:和NSURL [英] iPhone - Save URL without setURL:forKey: and NSURL
问题描述
无论如何使用没有setURL的NSUserDefaults保存URL:forKey:仅适用于iOS 4.0及更高版本?
Is there anyway to save a URL with NSUserDefaults without setURL:forKey: that is only available to iOS 4.0 and later?
我在本地使用fileURLWithPath加载HTML文件,它从一个介绍页面开始,用户可以点击进入任何内容。目前,每次用户重新开始时,都会将默认值加载到intro.htm。我希望能够将他们当前的页面保存到viewdiddissapear上的NSUserDefaults并在下次重新加载它,但除了setURL之外找不到任何解决方案:forKey:。那里的任何人都知道解决方案吗?
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?
推荐答案
您可以将URL转换为字符串:
You can turn the URL into a string:
[[NSUserDefaults standardUserDefaults]
setObject:[url absoluteString] forKey:@"url"];
反之亦然:
NSURL *url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults]
objectForKey:@"url"]];
这篇关于iPhone - 没有setURL保存URL:forKey:和NSURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!