[CIContext initWithOptions:]: 无法识别的选择器发送到 xcode8 中的实例 0x170400960

[CIContext initWithOptions:]: unrecognized selector sent to instance 0x170400960 in xcode8

运行 in ios8.3 , 但是 运行 in ios9 or 10 没有这个问题.

-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x170400960
2016-09-19 18:08:21.025 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x170400960'
*** First throw call stack:
(0x186d8c2d8 0x1985b00e4 0x186d933a4 0x186d90154 0x186c92ccc 0x1001c1e74 0x1001c1b7c 0x1001c143c 0x1001c1cfc 0x100311e0c 0x1003116d0 0x1001d7690 0x101f3025c 0x101f2fc08 0x101eee29c 0x103db8fd4 0x103db8f94 0x103dbdc28 0x186d437f8 0x186d418a0 0x186c6d2d4 0x1904836fc 0x18b832fac 0x100401fd8 0x198c2ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException

如果您查看崩溃报告,似乎 Xcode 8 在将 Swift 方法 CIContext(options: [String : Any]?) 转换为其 Objective-C 对应方法 + (CIContext *)contextWithOptions:(NSDictionary<NSString *,id> *)options;.

而是转换为 -[CIContext initWithOptions:],因此无法识别选择器。

一种可能的解决方法是像这样声明一个 Objective-C 类别:

@interface CIContext (Workaround)

+ (CIContext *)yourprefix_contextWithOptions:(NSDictionary<NSString *, id> *)options;

@end

@implementation CIContext (Workaround)

+ (CIContext *)yourprefix_contextWithOptions:(NSDictionary<NSString *, id> *)options {
    return [CIContext contextWithOptions:options];
}

@end

然后在你的模块桥接中导入这个类别 header 并用这个类别中的那个替换你原来的 CIContext init 调用。

我想这是一个可以通过 Xcode 更新修复的编译问题。同时,此解决方法可能会有所帮助。