我正在使用 PromiseKit 框架版本 1.7.7(我需要使用这个版本,因为另一个框架需要它)。
所以,在这个使用PromiseKit框架的框架中有这个方法:
- (PMKPromise *)paymentTokenForCreditCard:(GNCreditCard *)creditCard {
NSDictionary *cardDict = [creditCard paramsDicionary];
NSString *jsonCard = [self getJSONStringFromDictionary:cardDict];
return [self encryptData:jsonCard]
.then(^(NSString *encryptedData){
NSDictionary *params = @{@"data":encryptedData};
return [self request:kGNApiRouteSaveCard method:@"POST" params:params];
})
.then(^(NSDictionary *response){
return [[GNPaymentToken alloc] initWithDictionary:response];
});
}
它展示了如何使用它的例子:
GNConfig *gnConfig = [[GNConfig alloc] initWithAccountCode:@"YOUR_ACCOUNT_CODE" sandbox:YES];
GNApiEndpoints *gnApi = [[GNApiEndpoints alloc] initWithConfig:gnConfig];
GNCreditCard *creditCard = [[GNCreditCard alloc] init];
creditCard.number = @"4012001038443335";
creditCard.brand = kGNMethodBrandVisa;
creditCard.expirationMonth = @"05";
creditCard.expirationYear = @"2018";
creditCard.cvv = @"123";
[gnApi paymentTokenForCreditCard:creditCard]
.then(^(GNPaymentToken *paymentToken){
NSLog(@"%@", paymentToken.token);
})
.catch(^(GNError *error){
NSLog(@"An error occurred: %@", error.message);
});
好吧,我是如何使用 Swift 而不是 Object-C 的,我正在尝试以这种方式使用它:
let gnConfig = GNConfig(accountCode: "3f62976bea79971730b67cd62806c256", sandbox: true)
let gnEndpoints = GNApiEndpoints(config: gnConfig)
let gnCreditCard: GNCreditCard! = GNCreditCard(number: "4012001038443335", brand: kGNMethodBrandVisa, expirationMonth: "05", expirationYear: "2018", cvv: "123")
gnEndpoints?.paymentToken(for: gnCreditCard).then({ tokenPagamento in
if let aToken = tokenPagamento?.token {
print("\(aToken)")
}
}).catch({ error in
if let aMessage = error?.message {
print("An error occurred: \(aMessage)")
}
})
它向我显示了这个错误:
Ambiguous reference to member 'then()'
我该如何解决?
最佳答案
试试下面的代码。 promise 的事情应该有效。根据您的需要修改它。
gnEndpoints?.paymentToken(for: gnCreditCard).then({ token -> () in
if let token = token as? GNPaymentToken {
print(token)
}
}, { (error) -> () in
// catch your error
})
关于objective-c - PromiseKit 框架 - 对成员 'then()' 的模糊引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50747469/