#if PLATFORM_IOS char buffer[256]={0}; snprintf(buffer, sizeof(buffer), "%s%s", getenv("HOME"),"/Documents"); FString DestPath = UTF8_TO_TCHAR(buffer); ELOG(TEXT("Env Documents Path is: %s"), *DestPath); NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; DestPath = UTF8_TO_TCHAR([documentPath UTF8String]); ELOG(TEXT("OC Documents Path is: %s"), *DestPath); #else FString DestPath = FPaths::ProjectPersistentDownloadDir(); #endif |


#include <Foundation/Foundation.h> #include <sqlite3.h> @interface SqliteMgr : NSObject { sqlite3 *_db; } /** * 获取单例 * @return 单利 */ + (instancetype)getInstance; /** * 打开指定的数据库 * @param db 数据库路径 * @return 是否打败成功 * BOOL */ - (BOOL)openDB:(NSString *)db; /** * 执行SQL * @param sql * SQL语句 * @return * BOOL */ - (BOOL)exec:(NSString *)sql; /** * 查询SQL * @param sql 查询SQL * @return 返回一个数组代表数据行 */ - (NSArray *)query:(NSString *)sql; /** * 查询第一条 * @param sql 查询第一条数据 * @return Key/Value */ - (NSDictionary *)queryFirst:(NSString *)sql; /** * 统计 * @param sql 统计数据的sql * @return 数据总数 */ - (double)count:(NSString *)sql; /** * 关闭链接 * @return Sqlite错误码 */ - (int)close; @end |
#include <Foundation/Foundation.h> #include "SqliteMgr.h" @implementation SqliteMgr { } static SqliteMgr *instance; + (instancetype)getInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; }); return instance; } /** * 打开数据库 * @param db * @return */ - (BOOL)openDB:(NSString *)db { NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *DBPath = [documentPath stringByAppendingPathComponent:db]; NSLog(@"数据库路径%@", DBPath); if (sqlite3_open(DBPath.UTF8String, &_db) != SQLITE_OK) { return NO; } else { return YES; //打开成功创建表 } } /** * 执行SQL * @param sql * SQL语句 * @return * bool */ - (BOOL)exec:(NSString *)sql { return sqlite3_exec(_db, sql.UTF8String, nil, nil, nil) == SQLITE_OK; } /** * 查询语句 * @param sql * SQL语句 * @return * 结果集 */ - (NSArray *)query:(NSString *)sql { sqlite3_stmt *pstmt; //结果集游标句柄 if (sqlite3_prepare_v2(_db, sql.UTF8String, -1, &pstmt, NULL) != SQLITE_OK) { NSLog(@"执行SQL失败%@", sql); return NULL; }//查询成功 NSMutableArray *dicArr = [[NSMutableArray alloc] init]; while (sqlite3_step(pstmt) == SQLITE_ROW) { //遍历游标 [dicArr addObject:[self stmt2Dict:pstmt]]; } sqlite3_finalize(pstmt); return dicArr; } /** * 查询第一个结果 * @param sql * @return */ - (NSDictionary *)queryFirst:(NSString *)sql { sqlite3_stmt *pstmt; //结果集游标句柄 if (sqlite3_prepare_v2(_db, sql.UTF8String, -1, &pstmt, NULL) != SQLITE_OK) { NSLog(@"执行SQL失败%@", sql); return NULL; }//查询成功 while (sqlite3_step(pstmt) == SQLITE_ROW) { //遍历游标 return [self stmt2Dict:pstmt]; } return nil; } /** * 将 sqlite3_stmt 转成 Dictionary * @param pstmt * sqlite3_stmt 指针 * @return * Dictionary */ - (NSDictionary *)stmt2Dict:(sqlite3_stmt *)pstmt { int columnCount = sqlite3_column_count(pstmt); //获取列数 NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; //初始化一个Dict存放单行记录 for (int i = 0; i < columnCount; i++) { const char *key = sqlite3_column_name(pstmt, i); //取列名 int type = sqlite3_column_type(pstmt, i); switch (type) { case SQLITE_INTEGER: { int value = sqlite3_column_int(pstmt, i); //整型 dict[[NSString stringWithUTF8String:key]] = @(value); break; } case SQLITE_FLOAT: { double value = sqlite3_column_double(pstmt, i); //浮点型 dict[[NSString stringWithUTF8String:key]] = @(value); break; } case SQLITE_TEXT: default: { const char *value = (const char *)(sqlite3_column_text(pstmt, i)); //字符型 dict[[NSString stringWithUTF8String:key]] = [NSString stringWithUTF8String:value]; break; } } } return dict; } /** * 执行统计类型语句,例如 COUNT(1) ,SUM(col),返回第一个记录 * @param sql * SQL语句 * @return * count */ - (double)count:(NSString *)sql { sqlite3_stmt *pstmt; //结果集游标句柄 if (sqlite3_prepare_v2(_db, sql.UTF8String, -1, &pstmt, NULL) != SQLITE_OK) { NSLog(@"执行SQL失败%@", sql); return 0; } while (sqlite3_step(pstmt) == SQLITE_ROW) { return sqlite3_column_double(pstmt, 0); } return 0; } /** * 关闭链接 * @return */ - (int)close { return sqlite3_close(_db); } @end |

<Error>: This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data. |
