The Javascript library that I load in my webview uses the local storage to do some it's functions. In b4a, I give webview access to the local storage using the following code,
I couldn't figure out a way to do this in B4i. After doing some research online and in the forum, I got the following inline Obj-C code to enable the storage using websiteDataStore property.
I'm not sure whether this is right as the webview looks like it still doesn't have access to the browser's local storage.
Any help on this is much appreciated.
Thanks
B4X:
Dim jwb As JavaObject = myWebview
Dim jset As JavaObject = jwb.RunMethod("getSettings", Null)
Dim r As Reflector
r.Target = jset
' Enable local storage
r.RunMethod2("setDomStorageEnabled", True, "java.lang.boolean")
' Disable cross-origin limits on File protocol
r.RunMethod2("setAllowFileAccess", True, "java.lang.boolean")
r.RunMethod2("setAllowFileAccessFromFileURLs", True, "java.lang.boolean")
r.RunMethod2("setAllowUniversalAccessFromFileURLs", True, "java.lang.boolean")
I couldn't figure out a way to do this in B4i. After doing some research online and in the forum, I got the following inline Obj-C code to enable the storage using websiteDataStore property.
Objective-C:
#If OBJC
#import <Foundation/Foundation.h>
- (WKWebViewConfiguration *) getconfig: ( WKWebViewConfiguration *)config
{
WKUserContentController* userController = [[WKUserContentController alloc]init];
[userController addScriptMessageHandler:self name:@"callback"];
config.userContentController = userController;
config.preferences.javaScriptEnabled = YES;
config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
config.suppressesIncrementalRendering = YES;
config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
return config;
}
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
if ([message.name isEqualToString:@"callback"]) {
[self.bi raiseEvent:nil event:@"jscallback:"params:@[message.body]];
}
}
#End If
I'm not sure whether this is right as the webview looks like it still doesn't have access to the browser's local storage.
Any help on this is much appreciated.
Thanks