我是靠谱客的博主 俊秀跳跳糖,这篇文章主要介绍iOS 工程 兼容64位 容易遇到的问题,现在分享给大家,希望可以做个参考。

tips:
相信目前大部分APP的工程框架已经是支持64bit,但是就在几天前,遇到一个公司几年前的框架,SQLCipher数据库加密,AES加密,ASI网络请求,JSONKit,ZipArchive。。全是32bit,全打包成了.a静态库,我曹,如果让工程支持64bit,那我岂不是要重新引入这些三方 /吓?但在废弃这个框架之前,确实需要这么干。

正文:

好在大部分用来打包.a文件的源文件都在gitlab上,我还能找到,这算是不幸中的万幸

1、AES替换,无问题

2、ASI替换,在”Target”->”Build Phases”->”Compile Source”中所有ASI 文件的compile Flags 设置”-fno-objc-arc” 兼容ARC

3、JSONKit替换,同2、

4、ZipArchive替换,同2、

error1:
当到这里的时候,编译发现一个错误”Implicit declaration of function ‘NSFileTypeForHFSTypeCode’ is invalid in C99”,
这是FMDB的问题,FMDatabaseAdditions.m中存在如下一段代码:我们需要在代码的外面做预编译处理

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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)setApplicationID:(uint32_t)appID { NSString *query = [NSString stringWithFormat:@"PRAGMA application_id=%d", appID]; FMResultSet *rs = [self executeQuery:query]; [rs next]; [rs close]; } - (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 // 结束

5、SQLCipher替换,重新配置了一个,详情见https://www.zetetic.net/sqlcipher/ios-tutorial/

error 2:
这个时候又出现了另一个问题crash:

复制代码
1
NSInvalidArgumentException -[__NSTaggedPointerString unsignedLongLongValue]: unrecognized selector sent to instance

定位到实体中的字典转模型方法中:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _undefinedProperties = [NSMutableDictionary dictionary]; [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { DCProperty *property = [[self class] propertyDictionary][key]; Class class = NSClassFromString(property.type); if ([class isSubclassOfClass:[DCObject class]]) { DCObject *object = [[class alloc] initWithDictionary:obj]; [self setValue:object forKey:key]; } else if (![obj isEqual:[NSNull null]]) { [self setValue:obj forKey:key]; ---------crash的地方 } }]; } return self; }

这个问题,是因为64bit中,NSString 中没有unsignedLongLongValue这个方法了, 而当字典中obj的类型是NSString类型,实体中的key对应的属性是NSUinteger类型,setValue:obj forKey:key 会自动做如下处理:
[obj unsignedLongLongValue] 将value转为对应的属性类型,这就导致64bit中找不到该方法而crash。我的解决是,对NSString写一个category,重新写一个unsignedLongLongValue的方法:

复制代码
1
2
3
-(NSUinteger)unsignedLongLongValue { return [self integerValue]; }

或者 避免 让系统做NSString->NSUInteger的类型装换

最后

以上就是俊秀跳跳糖最近收集整理的关于iOS 工程 兼容64位 容易遇到的问题的全部内容,更多相关iOS内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部