0

我正在开发一个类似测验的游戏项目,它使用 sqlite db 来存储数据。一切正常,即在“调试”配置中读取和写入数据库,游戏按预期工作。

但是,当我在发布配置中构建相同的游戏时。sqlite“插入”和“更新”语句不能正常工作。由于 sqlite db 读/写,程序在几次播放后崩溃。

我在互联网上搜索了答案,发现很少有建议说这是发布配置中的优化问题。

这是我在 sqlite db 中插入新播放器的代码。

- (void) insertPlayerWithName:(NSString *) playerName {

@try
{
    [self openDatabase];

    Player *p = [[Player alloc] init];
    p.name = playerName;
    p.energyRefillDate = [self getStringDateFromNSDate:[NSDate dateWithTimeIntervalSinceNow:100000]];

    NSLog(@"Date  : %@", p.energyRefillDate);
    NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO Player VALUES ('%@', %d, %d, %d, %d, %d, %d, %d, %d, %d, '%@', %d)", p.name, p.knop, p.gold, p.energy, p.karma, p.level, p.keyOfEnergy, p.keyOfWisdom, p.keyOfStrength, p.premium, p.energyRefillDate, p.numQuestsCompleted];

    char *error;
    if ( sqlite3_exec(_sqliteDBConnection, [insertSQL UTF8String], NULL, NULL, &error) != SQLITE_OK )
    {
        NSLog(@"Error While Inserting Player : %@", [NSString stringWithUTF8String:error] );
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setObject:playerName forKey:@"CurrentPlayer"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        sqlite3_close(_sqliteDBConnection);
    }
    [p release];
}
@catch (NSException *exception)
{
    NSLog(@"An exception while Error While Inserting Player in Sqlite :%@", exception);
}
@finally
{
    sqlite3_close(_sqliteDBConnection);
}
}

任何形式的帮助、建议、提示都将受到高度赞赏。提前感谢您花时间阅读问题。

4

1 回答 1

0

I found the issue. The issue was with the C Preprocessor Flag NS_BLOCK_ASSERTIONS=1 in release configuration.

When I removed this assertion, the app worked as expected. I hope it would help someone out there who may face this problem.

于 2013-04-15T04:23:15.353 回答