6

アプリがオフラインで動作するように、事前に入力されたデータベースを Web アプリで使用したいと考えています。PhoneGap / Cordova (2.0) の最新バージョンでこれを行うにはどうすればよいですか?

この質問が以前に尋ねられたことは知っていますが、現在のバージョンの cordova と iOS に比べてすべての回答が古くなっているようです

https://github.com/atkinson/phonegap-prepopulate-dbは 2 年間更新されてい ませんhttps://github.com/davibe/Phonegap-SQLitePluginは 7 か月間更新されておらず、1.7 用です

私はここに投稿を見つけました: http://www.raymondcamden.com/index.cfm/2012/7/27/Guest-Blog-Post-Shipping-a-populated-SQLite-DB-with-PhoneGapはこれが唯一の方法です?

また、私はiOS 6を使用していることに注意する必要があります

4

3 に答える 3

2

iOS6 で Cordova 2.7 に次のプラグインを使用しましたが、1 日前に更新されたばかりです。https://github.com/pgsqlite/PG-SQLitePlugin-iOS

ここにもAndroidバージョンがあります。問題の一部は、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;

}

-(void)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];

}

お役に立てれば...

于 2013-09-04T20:20:26.830 に答える