更新
2015 年8 月 19 日- 错误似乎已在3.13
更新中得到修复,尽管他们在更新日志中列出的唯一内容是"Fixed an issue which caused crashes when using setCampaignParametersFromUrl"
. 想拿就拿吧。
2015 年6 月 8 日- 仍然遇到这个问题。如果我禁用自动发送事件 ( [GAI sharedInstance].dispatchInterval = -1;
),那么我仍然会收到错误。因此,我假设问题在于将事件插入到 Google Analytics SQLite 数据库中,不知何故,我自己的当前正在进行的数据库语句正在变成void
.
2015 年6 月 10 日- 仍然遇到崩溃。尝试手动移除我的控制器扩展GAITrackedViewController
和发送createScreenView
轨道,而崩溃频率没有变化。
2015 年6 月 25 日- 仍然遇到崩溃。
介绍
我已将它添加Google Analytics SDK 3.12
到我的 iPhone 应用程序中,一切都按预期运行 - 我运行该应用程序,可以在 Web 界面上看到我设置的所有点击和事件。
我AppDelegate
在顶部的右侧初始化 SDK didFinishLaunchingWithOptions
,如下所示:
[[GAI sharedInstance] trackerWithTrackingId:GOOGLE_ANALYTICS_ID];
问题
但是,我发现当我自己尝试使用 SQLite 时,运行 Google Analytics 会产生错误。它们可能表现为严重错误,例如:
"Database disk image is malformed"
然后即时崩溃"Disc i/O error"
每当我运行查询时(虽然不会崩溃)
它们还可能导致我自己的 SQLite 查询失败,例如:
if (! sqlite3_prepare_v2(_db, [sql UTF8String], -1, &_statement, NULL) == SQLITE_OK) {`
// ..
// ..
if (sqlite3_step(_statement) == SQLITE_ROW) {
将随机导致以下错误:
sqlite3_prepare_v2 EXC_BAD_ACCESS (code=1, address=0x6800000000)
如果我注释掉 SDK 初始化,那么一切都会恢复到难以置信的稳定。再次取消注释它会在一分钟内使应用程序崩溃。
抢先答题
我在运行 8.3 (12F70) 的 iPhone 6 上运行它。
已尝试卸载并重新安装该应用程序。
我已经添加了谷歌分析工作的所有先决条件;
.m
库中的所有文件、libGoogleAnalyticsServices.a
文件以及Linked Frameworks and Libraries
.我也有 Crashlytics,但尝试从代码 ( ) 中将其注释掉并从 中
[Fabric with:@[CrashlyticsKit]];
删除其库,Linked Frameworks and Libraries
结果完全相同。
代码
设置班级
// In didFinishLaunchingWithOptions
[Db setup];
[Db connect];
访问类
Db * db = [[Db alloc] init];
if ([db prepare:@"SELECT * FROM `table` WHERE `id` = ?" withBindings:@[@"123"]]) {
while ([db stepThrough]) {
// ..
}
}
[db finalise];
班上
(已在注释中指出错误出现的位置)
@implementation Db
static sqlite3 * _db;
static NSString * _dbPath;
#pragma mark - Setup
+ (BOOL)setup {
NSString * sqlBundlePath = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"];
NSString * documentsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString * sqlDocumentPath = [[documentsFolder stringByAppendingPathComponent:@"db"] stringByAppendingPathExtension:@"sqlite"];
NSFileManager * fileManager = [NSFileManager defaultManager];
if (! [fileManager fileExistsAtPath:sqlDocumentPath]) {
NSError * error;
BOOL success = [fileManager copyItemAtPath:sqlBundlePath toPath:sqlDocumentPath error:&error];
if (! success) {
return NO;
}
}
_dbPath = sqlDocumentPath;
return YES;
}
+ (BOOL)connect {
sqlite3_config(SQLITE_CONFIG_SERIALIZED);
return sqlite3_open([_dbPath UTF8String], &_db);
}
#pragma mark - Querying
- (BOOL)prepare:(NSString *)sql withBindings:(NSArray *)bindings {
// ERROR CAN OCCUR ON THE FOLLOWING LINE
if (! sqlite3_prepare_v2(_db, [sql UTF8String], -1, &_statement, NULL) == SQLITE_OK) {
NSLog(@"Error whilst preparing query: %s", sqlite3_errmsg(_db));
sqlite3_finalize(_statement);
return NO;
}
for (int i = 0; i < [bindings count]; i++) {
sqlite3_bind_text(_statement,
i + 1,
[bindings[i] isKindOfClass:[NSNull class]] ? [@"" UTF8String] : [bindings[i] UTF8String],
-1,
SQLITE_TRANSIENT);
}
return YES;
}
- (BOOL)stepThrough {
// ERROR CAN OCCUR ON THE FOLLOWING LINE
if (sqlite3_step(_statement) == SQLITE_ROW) {
return YES;
}
sqlite3_finalize(_statement);
return NO;
}
- (void)finalise {
sqlite3_finalize(_statement);
}
@end