我已经为带有 iOS6 的 Cordova 2.7 使用了以下插件,我看到它刚刚在一天前更新。https://github.com/pgsqlite/PG-SQLitePlugin-iOS
他们这里也有安卓版本。问题的一部分是PhoneGap的变化,所以经常保持插件最新可能会很耗时,所以它们会失效。这是我在这个项目中使用的 AppDelegate.m 中的 init 方法的代码http://www.binpress.com/app/conference-core-ios-for-phonegap/1483
请记住,您有时需要擦除 iOS 模拟器,以便它重新加载与应用程序相关的文件。
- (id)init{
NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
如果 __has_feature(objc_arc)
NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
别的
NSURLCache* sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease];
万一
[NSURLCache setSharedURLCache:sharedCache];
databaseName = @"SomeCoolDatabase.db";
NSLog(@"databaseName: %@", databaseName);
databasePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
NSLog(@"databasePath: %@", databasePath);
databaseFile = [databasePath stringByAppendingPathComponent:databaseName];
NSLog(@"databaseFile: %@", databaseFile);
// Execute the "checkAndCreateDatabase" function
[self checkAndCreateDatabase];
self = [super init];
return self;
}
-(无效)checkAndCreateDatabase {
// Check if the SQL database has already been saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databaseFile];
// If the database already exists then return without doing anything
if(success){
NSLog(@"Database Present");
return;
} else {
NSLog(@"database not present");
}
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Create the database folder structure
[fileManager createDirectoryAtPath:databasePath withIntermediateDirectories:YES attributes:nil error:NULL];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databaseFile error:nil];
[fileManager release];
}
希望这可以帮助...