我按照教程在iOS设备上使用二进制文件编译SQLCipher:http://sqlcipher.net/sqlcipher-binaries-ios-and-osx/
我对构建设置进行了一些更改,添加了标头搜索路径和C标志。然后在测试了sqlcipher的编译之后,我没有得到二进制文件的任何错误,但是之前在FMDB中不存在的错误开始显示如下:
FMDatabaseAdditions.m:137:19:函数的隐式声明' NSFileTypeForHFSTypeCode'在C99`中无效
FMDatabaseAdditions.m:137:19:' int'的隐式转换到#NSString *' ARC不允许
FMDatabaseAdditions.m:137:15:不兼容的整数到指针转换初始化' NSString * __ strong'表达式为' int'`
FMDatabaseAdditions.m:158:96:类型' NSUInteger'的值不应该用作格式参数;添加一个显式的强制转换为' unsigned long' instead`
FMDatabaseAdditions.m:161:28:隐式声明函数' NSHFSTypeCodeFromFileType'在C99`中无效
答案 0 :(得分:19)
在项目中使用目标时会发生此错误。只有在针对Mac OS目标编译项目时才需要NSFileTypeForHFSTypeCode,如果target是iPhone,则不应使用NSFileTypeForHFSTypeCode。实际上,在新版本的XCode上,即使您的项目以iPhone为目标,也会出现错误。 旧答案:
所以我们必须重写applicationIDString实现并放置条件标志:
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
- (NSString*)applicationIDString {
NSString *s = NSFileTypeForHFSTypeCode([self applicationID]);
assert([s length] == 6);
s = [s substringWithRange:NSMakeRange(1, 4)];
return s;
}
#endif
如果TARGET_OS_MAC不会替换!TARGET_OS_IPHONE的需要,因为TARGET_OS_IPHONE实际上是TARGET_OS_MAC的变体。因此,为了避免编译错误,请添加#if TARGET_OS_MAC&& !TARGET_OS_IPHONE
也低于该部分代码:
- (void)setApplicationIDString:(NSString*)s {
if ([s length] != 4) {
NSLog(@"setApplicationIDString: string passed is not exactly 4 chars long. (was %ld)", [s length]);
}
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
[self setApplicationID:NSHFSTypeCodeFromFileType([NSString stringWithFormat:@"'%@'", s])];
#endif
}
新答案:
我更新了代码并重新安排了方法,以便在FMDatabaseAdditions.m 的范围(条件)中进行更多分组:
#if SQLITE_VERSION_NUMBER >= 3007017
- (uint32_t)applicationID {
uint32_t r = 0;
FMResultSet *rs = [self executeQuery:@"pragma application_id"];
if ([rs next]) {
r = (uint32_t)[rs longLongIntForColumnIndex:0];
}
[rs close];
return r;
}
- (void)setApplicationID:(uint32_t)appID {
NSString *query = [NSString stringWithFormat:@"pragma application_id=%d", appID];
FMResultSet *rs = [self executeQuery:query];
[rs next];
[rs close];
}
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
- (NSString*)applicationIDString {
NSString *s = NSFileTypeForHFSTypeCode([self applicationID]);
assert([s length] == 6);
s = [s substringWithRange:NSMakeRange(1, 4)];
return s;
}
- (void)setApplicationIDString:(NSString*)s {
if ([s length] != 4) {
NSLog(@"setApplicationIDString: string passed is not exactly 4 chars long. (was %ld)", [s length]);
}
[self setApplicationID:NSHFSTypeCodeFromFileType([NSString stringWithFormat:@"'%@'", s])];
}
#endif
#endif
还要避免其他警告,我修改了FMDatabaseAdditions.h
#if SQLITE_VERSION_NUMBER >= 3007017
///-----------------------------------
/// @name Application identifier tasks
///-----------------------------------
/** Retrieve application ID
@return The `uint32_t` numeric value of the application ID.
@see setApplicationID:
*/
- (uint32_t)applicationID;
/** Set the application ID
@param appID The `uint32_t` numeric value of the application ID.
@see applicationID
*/
- (void)setApplicationID:(uint32_t)appID;
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
/** Retrieve application ID string
@return The `NSString` value of the application ID.
@see setApplicationIDString:
*/
- (NSString*)applicationIDString;
/** Set the application ID string
@param string The `NSString` value of the application ID.
@see applicationIDString
*/
- (void)setApplicationIDString:(NSString*)string;
#endif
#endif
答案 1 :(得分:0)
它看起来是FMDB中的一个错误(https://github.com/ccgus/fmdb/issues/163) - 有问题的代码只能在OSX中编译。