Open remisture opened 6 years ago
Check out the https://github.com/paulpatarinski/cordova-plugin-migrate-localstorage fork for ionic-webview
@paulpatarinski I've tried your fork of this plugin with ionic-webview 1.1.16 (as pointed out in your disclaimer) however it does not copy the old localStorage (from the UIWebView) to the WKWebView.
I do see in XCode the log that it sees there's no localStorage (as the NSLog of "No existing localstorage data found for WKWebView. Migrating data from UIWebView" is posted), so it attempts to copy over, but then when I check the localStorage it did not actually copy over. Any suggestions what could be the issue?
@hellkith Did you get any solution for coping the old localStoage to the WKWEbView for iOS?
yes, I changed some of the code in the MigrateLocalStorage.m. Below is my full file with what it does. I had to add several extra copies as it didn't copy the correct files at all.
IF you replace the contents of your MigrateLocalStorage.m it should work. Do note that it will only work if there is no WKWebView yet. Seeing it shouldn't be copying over it again once there is a WKWebview as it will place back the old storage or delete the current storage.
So easy way to test this is to have an install of your app with the UIWebView, make a backup of that via XCode (Window -> devices -> click on app -> cogwheel -> download container). This way you can always replace the container with the UIWebView again if it fails. Then run the update on the app so that it upgrades to the WKWebView and it should have copied it over.
`#import "MigrateLocalStorage.h"
@implementation MigrateLocalStorage
// Bail out if source file does not exist if (![fileManager fileExistsAtPath:src]) { return NO; }
// Bail out if dest file exists
if ([fileManager fileExistsAtPath:dest]) {
return NO;
}
// create path to dest
if (![fileManager createDirectoryAtPath:[dest stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil]) {
return NO;
}
// copy src to dest
return [fileManager copyItemAtPath:src toPath:dest error:nil];
}
(void) migrateLocalStorage { // Migrate UIWebView local storage files to WKWebView. Adapted from // https://github.com/Telerik-Verified-Plugins/WKWebView/blob/master/src/ios/MyMainViewController.m
NSString appLibraryFolder = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString original;
if ([[NSFileManager defaultManager] fileExistsAtPath:[appLibraryFolder stringByAppendingPathComponent:@"WebKit/LocalStorage/file__0.localstorage"]]) { original = [appLibraryFolder stringByAppendingPathComponent:@"WebKit/LocalStorage"]; } else { original = [appLibraryFolder stringByAppendingPathComponent:@"Caches"]; }
NSString originalFile = [appLibraryFolder stringByAppendingPathComponent: @"WebKit/LocalStorage/file__0.localstorage"]; NSString originalFileTarget = [appLibraryFolder stringByAppendingPathComponent:@"Caches/file0.localstorage"]; NSString* originalFileshm = [appLibraryFolder stringByAppendingPathComponent:@"WebKit/LocalStorage/file0.localstorage-shm"]; NSString originalFileTargetshm = [appLibraryFolder stringByAppendingPathComponent:@"Caches/file__0.localstorage-shm"]; NSString originalFilewal = [appLibraryFolder stringByAppendingPathComponent:@"WebKit/LocalStorage/file0.localstorage-wal"]; NSString* originalFileTargetwal = [appLibraryFolder stringByAppendingPathComponent:@"Caches/file0.localstorage-wal"];
original = [original stringByAppendingPathComponent:@"file__0.localstorage"];
NSString* target = [[NSString alloc] initWithString: [appLibraryFolder stringByAppendingPathComponent:@"WebKit"]];
// the simulutor squeezes the bundle id into the path
NSString* bundleIdentifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
target = [target stringByAppendingPathComponent:bundleIdentifier];
target = [target stringByAppendingPathComponent:@"WebsiteData/LocalStorage/http_localhost_8080.localstorage"];
[self copyFrom:originalFile to:originalFileTarget];
[self copyFrom:originalFileshm to:originalFileTargetshm];
[self copyFrom:originalFilewal to:originalFileTargetwal];
// Only copy data if no existing localstorage data exists yet for wkwebview
if (![[NSFileManager defaultManager] fileExistsAtPath:target]) {
NSLog(@"No existing localstorage data found for WKWebView. Migrating data from UIWebView");
[self copyFrom:original to:target];
[self copyFrom:[original stringByAppendingString:@"-shm"] to:[target stringByAppendingString:@"-shm"]];
[self copyFrom:[original stringByAppendingString:@"-wal"] to:[target stringByAppendingString:@"-wal"]];
}
}
@end`
Hi,
Great plugin.
Will it also work with this version: https://github.com/ionic-team/cordova-plugin-ionic-webview ?