条带错误"create token with card(_:completion:) is unavailable"



在此行中,错误是显示。有人能告诉我犯了什么错误吗?

 Stripe.createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in
        self.handleToken(token)
最近在

pod 中更新 Stripe 后,我遇到了同样的问题。该方法已弃用。相反,您可以使用以下代码:

STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in     
})

它采用相同的参数。

更新

感谢@Christine和@Keyhole150

条纹 API 中的此函数现已更改为

STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in     
})

谢谢,@Shali!您的提示很有帮助。

对于那些像我这样的初学者,您可能仍然会收到错误。如果您在添加sharedClient()之前遇到错误,指示调用中存在额外的参数,或者在添加sharedClient()后无法调用createTokenWithCard,则使完成参数可选会有所帮助(如STPToken?NSError?)。

正如Christine所提到的,该方法现在使用Optionals,因此它如下所示:

    STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in     
    })

对于使用最新条纹pod的objective-c

#import "Stripe.h"
STPCardParams *cardParams = [[STPCardParams alloc] init];
cardParams.number = @"4242424242424242";
cardParams.expMonth = 10;
cardParams.expYear = 2018;
cardParams.cvc = @"123";
[[STPAPIClient sharedClient] createTokenWithCard:cardParams completion:^(STPToken *token, NSError *error) {
    if (token == nil || error != nil) {
        // Present error to user...
        NSLog(@"%@",error.description);
        return;
    }
NSLog(@"token.tokenId :: %@",token.tokenId);
}];

相关内容

最新更新