我想要在线工作的应用程序以及离线工作的示例WhatsApp
。为此,我必须同步来自web服务的数据,然后将其存储在sqlitedb文件中。我希望无论谁安装这个应用程序,都能在数据库文件中自动保存数据。我必须从iTunes添加数据库文件吗?
我不想使用核心数据概念。它有可能和申请一起在那里吗?
就像在安卓系统中一样,有一种叫做缓存的东西可以存储db文件,所以在ios中有什么规定吗?
+(int)insert_In_AdverImage:(NSString *)strid ImageName:(NSString *)strimg Isshow:(NSString *)strshow LastUpdateId:(NSString *)date isdelete:(NSString *)isdelete Sortorder:(int)sortOrder{
sqlite3 *database;
int retValue = 0;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *tempSQL = [[NSString alloc] initWithFormat:@"INSERT INTO ADVERIMAGE(advId ,advimg ,isshow ,LastUpdateId ,IsDelete ,SortorderId ) VALUES ('%@', '%@', '%@', '%@', '%@', '%d')", strid, strimg, strshow, date, isdelete, sortOrder];
const char *sqlStatement = [tempSQL cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3_stmt *compiledStatement;
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
sqlite3_step(compiledStatement);
retValue = (int)sqlite3_last_insert_rowid(database);
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
return retValue;
}
工作良好。但应用程序包中的数据库文件仍然是空的。我知道,每当我们插入一些东西时,它都会插入文档中,如果我们必须看到插入的数据,我们必须从文档中获取
提前感谢
如有任何帮助,我们将不胜感激。
是。可能的
您可以将SQlite DB存储在应用程序的文档目录中。您需要编写自己的查询来打开数据库,插入数据,从数据库检索数据。
查看以下教程了解您的需求:http://www.appcoda.com/sqlite-database-ios-app-tutorial/
希望能有所帮助。
以下功能用于插入:
NSArray *docsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docsDirectory objectAtIndex:0];
NSString *databasePath = [docPath stringByAppendingPathComponent:@"Database.sqlite"];
sqlite3 *dbHandler;
const char *dbPath = [databasePath UTF8String];
sqlite3_stmt *sqlStmt;
if(sqlite3_open(dbPath, &dbHandler) == SQLITE_OK)
{
if (sqlite3_prepare_v2(dbHandler, [queryString UTF8String], -1, &sqlStmt, NULL) == SQLITE_OK)
{
if (sqlite3_step(sqlStmt) == SQLITE_DONE)
{
NSLog(@"Data Inserted");
}
else
{
NSLog(@"Not inserted");
}
}
else
{
NSLog(@"Failed to Insert data -InsertDataFunc");
}
sqlite3_close(dbHandler);
}