objective-c iOS WebKit local storage local-storage

Source: Internet
Author: User

I have a cocoa/objective-c application that embeds a WebKit Web view. I need to open the database support and local storage. I know it can be done-I have it working in safari-but I can't find an example of how to set this up in my own application. I found this (unanswered) question so it provides an example, but just as it did not work. And in fact, (setdatabasesenabled,setlocalstorageenabled) There is no definition in my webkit. (Xcode's 3.2.5), though they seem to exist, if I define them myself. Can anyone provide examples of WebKit-based cocoa applications that enable local database storage? Thank codego.net very much, if so! Update: I have a job ... I am through "database" and "local Storage", which is obviously something completely different. Here's the code for the job:

WebPreferences* prefs = [webView preferences];[prefs _setLocalStorageDatabasePath:@"~/Library/Application Support/MyApp"];[prefs setLocalStorageEnabled:YES];

Such works, but it needs _setlocalstoragedatabasepath, no App store so I fix the problem now: there is no way to make this work not used, I found the Webdatabasedirectory preference key in this answer, Where the database can be controlled. But I can't find the corresponding key locally stored anywhere in the source. Or is there a way to force a locally stored database, so the Webdatabasedirectory key? Any idea?
This address: codego.net/234678/

--------------------------------------------------------------------------------------------------------------- ----------
1. I submitted this code in Mac App Store, Apple approved:

WebPreferences* prefs = [webView preferences];[prefs _setLocalStorageDatabasePath:@"~/Library/Application Support/MyApp"];[prefs setLocalStorageEnabled:YES];

Whether they will continue to approve, I don't know, but they allow it for my application for 2011-01-29. Update: They also approved the version of the updated application, so it has gone through two of times.
2. I'm going to take the JavaScript to objective-c the approach and store all the core data. Set the Localstorage to false and then build a JS object and instance "Localstorage" with my JavaScript developers will not know the difference codego.net, and I have done things with air (basic). There is another way to leave localstorage intact, even if it does not actually store them in the persistence database. This can be done iteratively in JavaScript and manipulated from there, but I think it would be simply to replace the object with your own.
3. After a lot of pain, I found a way to make local storage and keep it running across applications. This solution is specifically for OSX, but it may be good for iOS. Download and add this header file to your project. It does not include the WebKit distribution in Xcode. Click on Download WebStorageManagerPrivate.h to add to it in the following lines:

static NSString* _storageDirectoryPath();+ (NSString *)_storageDirectoryPath;

This allows you to retrieve the directory location of the WebKit local storage track database. This is due to a bug in WebKit important, if you do not store the WebView files in the localstorage of the trace database in the directory, they will all be deleted by all other running your application. I didn't see a way to change this location for a single application in the Webstoragemanager code. It is always read from a priority. Including WebStorageManagerPrivate.h in your appdelegate.

#include "WebStorageManagerPrivate.h"

You need to download and include the other end of the distribution in your project that is not included in Xcode. Save it as WebPreferencesPrivate.h click to download WebPreferencesPrivate.h including WebPreferencesPrivate.h in your appdelegate.

#include "WebPreferencesPrivate.h"

below Applicationdidfinish The code in the launching handler is initialized and enabled in Localstorage. You have a Iboutlet ' Web View ' for the WebView your code

 nsstring* DbPath = [Webstoragemanager _storagedirectorypath]; webpreferences* prefs = [Self.webview preferences];  nsstring* Localdbpath = [Prefs _localstoragedatabasepath]; PATHS must MATCH!!!! Otherwise localstorage file is erased when starting program if ([localdbpath isequaltostring:dbpath] = = NO) {[Prefs SetA Utosaves:yes];  SET PREFS AUTOSAVE First otherwise settings aren ' t saved. Define Application Cache Quota static const unsigned long long Defaulttotalquota = 10 * 1024 * 1024; 10MB static const unsigned long long Defaultoriginquota = 5 * 1024 * 1024;  5MB [Prefs Setapplicationcachetotalquota:defaulttotalquota];  [Prefs Setapplicationcachedefaultoriginquota:defaultoriginquota];  [Prefs Setwebglenabled:yes];  [Prefs Setofflinewebapplicationcacheenabled:yes];  [Prefs Setdatabasesenabled:yes]; [Prefs setdeveloperextrasenabled:[[nsuserdefaults Standarduserdefaults] Boolforkey: @ "developer"]; #ifdef DEBUG [ Prefs Setdeveloperextrasenabled:yes]; #endif [Prefs _setlOcalstoragedatabasepath:dbpath];  [Prefs Setlocalstorageenabled:yes]; [Self.webview Setpreferences:prefs]; }

I hope this can help others have been working hard, or still struggling with this problem until it is fixed correctly in WebKit.

objective-c iOS WebKit local storage local-storage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.