开发者

Using NSUserDefaults from javascript webapp

开发者 https://www.devze.com 2022-12-09 17:17 出处:网络
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 definit

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消