Using NSUserDefaults from javascript webapp
I need to store and access preferences (like colour开发者_开发技巧, etc.) from a javascript webapp.. Is there some webkit access to the NSUserDefaults? (or maybe CFPreferences ?)
YES. There most definitely IS a way.. Check out JSUserDefaults…
Real simple drop-in replacement for UIWebView. Just change the class membership of the web view in your nib (or create it programmatically, that oughta work too) and it'll let you access NSUserDefaults through the JSUserDefaults object. Like this:
[[NSUserDefaults standardUserDefaults] setObject:@"Bar"
forKey:@"Foo"];
(...some time later...)
<script type="text/javascript">
document.write(JSUserDefaults.objectForKey("Foo"));
</script>
You can also set objects. Any plist object should work fine—arrays, dictionaries, strings, numbers. Other things might be dicey.
In a word... no. However, WebKit supports HTML 5 things like local storage - check this article out on the ADC site.
精彩评论