Skip to content

Instantly share code, notes, and snippets.

@orbitaloop
orbitaloop / migration_localstorage.m
Created October 29, 2012 19:29
LocalStorage/WebSQL migration from iOS 5.0 (or before) to iOS 5.1
//Valid Storage path :
NSString* library = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *WebSQLSubdir = (IsAtLeastiOSVersion(@"5.1")) ? @"Caches" : @"WebKit/Databases";
NSString *WebSQLPath = [library stringByAppendingPathComponent:WebSQLSubdir];
NSString *WebSQLDb = [WebSQLPath stringByAppendingPathComponent:@"file__0"];
NSString *WebSQLDbFile = [WebSQLDb stringByAppendingPathComponent:@"0000000000000001.db"];
NSError *attributesError = nil;
NSFileManager* fileManager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:WebSQLDbFile error:&attributesError];
@orbitaloop
orbitaloop / executeSqlBridgeForPhonegapSQLitePlugin.js
Created March 10, 2012 01:03
executeSql Bridge For PhonegapSQLitePlugin (because there are some differences between the WebSQL API and the plugin)
/* to use WebSQL or the SQLite plugin (https://github.com/davibe/Phonegap-SQLitePlugin) with the same function) */
executeSqlBridge: function(tx, sql, params, dataHandler, errorHandler) {
var self = this;
if (typeof self.db.dbPath !== 'undefined') {
//Native SQLite DB with phonegap : https://github.com/davibe/Phonegap-SQLitePlugin/
//this is a native DB, the method signature is different:
var sqlAndParams = [sql].concat(params);
var cb = function(res) {
@orbitaloop
orbitaloop / AppDelegate_webViewDidStartLoad.m
Created March 10, 2012 00:50
Fix to copy the WebSQL DB to the document Folder (because iOS5.1 use now the Library/Caches folder and doesn't do the migration)
/* Based on the code of ScottP and Gaurav Tomar ( http://gauravstomar.blogspot.com/2011/08/prepopulate-sqlite-in-phonegap.html */
/* Put that code in AppDelegate.m */
- (void)webViewDidStartLoad:(UIWebView *)theWebView
{
NSString *databaseName = @"0000000000000001.db";
//Get Documents path
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];