自从我升级到 Xcode 9 后,我的 BTAPIClient.m 文件中出现了一个新错误。
@defaultFirst 变量触发以下错误:
Object of type 'NSNumber *' is not compatible with dictionary value type 'NSString *' .
它发生在以下代码行中:
parameters:@{@"default_first": @(defaultFirst)}
我无法找到记录此错误的其他人。我没有修改任何代码,这是一个新的 Cocoapods 安装。
- (void)fetchPaymentMethodNonces:(BOOL)defaultFirst completion:(void (^)(NSArray <BTPaymentMethodNonce *> *, NSError *))completion {
if (!self.clientToken) {
NSError *error = [NSError errorWithDomain:BTAPIClientErrorDomain code:BTAPIClientErrorTypeNotAuthorized userInfo:@{ NSLocalizedDescriptionKey : @"Cannot fetch payment method nonces with a tokenization key", NSLocalizedRecoverySuggestionErrorKey : @"This endpoint requires a client token for authorization"}];
if (completion) {
completion(nil, error);
}
return;
}
[self GET:@"v1/payment_methods"
parameters:@{@"default_first": @(defaultFirst),
@"session_id": self.metadata.sessionId}
completion:^(BTJSON * _Nullable body, __unused NSHTTPURLResponse * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
if (error) {
completion(nil, error);
} else {
NSMutableArray *paymentMethodNonces = [NSMutableArray array];
for (NSDictionary *paymentInfo in [body[@"paymentMethods"] asArray]) {
BTJSON *paymentInfoJSON = [[BTJSON alloc] initWithValue:paymentInfo];
BTPaymentMethodNonce *paymentMethodNonce = [[BTPaymentMethodNonceParser sharedParser] parseJSON:paymentInfoJSON withParsingBlockForType:[paymentInfoJSON[@"type"] asString]];
if (paymentMethodNonce) {
[paymentMethodNonces addObject:paymentMethodNonce];
}
}
completion(paymentMethodNonces, nil);
}
}
});
}];
最佳答案
我在使用 Cocoapods 的项目中遇到了同样的问题。
确保你没有更新你的依赖项:
pod install
不是 update
关于Xcode 9 的 Braintree 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46382149/