【发布时间】:2015-01-05 13:58:38
【问题描述】:
我是 iOS 编程新手。
我正在尝试将 Stripe 集成到我的 iOS app。
它给了我以下错误。
第一次抛出调用堆栈:( 0 CoreFoundation
0x037c1946 异常预处理 + 182 1 libobjc.A.dylib
0x03075a97 objc_exception_throw + 44 2 核心基础
0x037c186d +[NSException raise:format:] + 141 3 ValenX
0x00343c63 +[Stripe validateKey:] + 163 4 ValenX
0x0034539a +[条纹 createTokenWithCard:publishableKey:operationQueue:completion:] + 314 5 ValenX 0x0034612e +[条纹 createTokenWithCard:publishableKey:completion:] + 222 6 ValenX
0x00345fff +[Stripe createTokenWithCard:completion:] + 175 7 ValenX 0x000cf59f -[V_BuyStripeVC saveButtonAction:] + 879 8
libobjc.A.dylib 0x0308b7cd -[NSObject performSelector:withObject:withObject:] + 84 9 UIKit
0x01aea23d -[UIApplication sendAction:to:from:forEvent:] + 99 10 UIKit 0x01aea1cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64 11 UIKit
0x01c1de86 -[UIControl sendAction:to:forEvent:] + 69 12 UIKit
0x01c1e2a3-[UIControl_sendActionsForEvents:withEvent:] + 598 13 UIKit 0x01c1d50d -[UIControl touchesEnded:withEvent:] + 660 14 UIKit
0x01b3a60a -[UIWindow _sendTouchesForEvent:] + 874 15 UIKit
0x01b3b0e5 -[UIWindow sendEvent:] + 791 16 UIKit
0x01b00549 -[UIApplication sendEvent:] + 242 17 UIKit
0x01b1037e _UIApplicationHandleEventFromQueueEvent + 20690 18 UIKit 0x01ae4b19 _UIApplicationHandleEventQueue + 2206 19 核心基础
0x036e51df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 20 CoreFoundation 0x036daced __CFRunLoopDoSources0 + 253 21 CoreFoundation 0x036da248 __CFRunLoopRun + 952 22 CoreFoundation
0x036d9bcb CFRunLoopRunSpecific + 443 23 核心基础
0x036d99fb CFRunLoopRunInMode + 123 24 图形服务
0x0510624f GSEventRunModal + 192 25 图形服务
0x0510608c GSEventRun + 104 26 UIKit
0x01ae88b6 UIApplicationMain + 1526 27 ValenX
0x000cf0ce top_level_code + 78 28 ValenX
0x000cf10b 主 + 43 29 libdyld.dylib
0x04105ac9 start + 1 ) libc++abi.dylib: 以未捕获的方式终止 NSException 类型的异常
下面是代码。
#import <AFNetworking/AFNetworking.h>
#import "Stripe.h"
#import "V_BuyStripeVC.h"
#import "PTKView.h"
#import "STPToken.h"
#define STRIPE_TEST_PUBLIC_KEY @"pk_test_vh4FFxERgMGtcs344RkWEfpC"
#define STRIPE_TEST_POST_URL @"http://s547905537.onlinehome.us/ValenX/serverauth.json"
@interface V_BuyStripeVC ()<PTKViewDelegate>
@property(weak, nonatomic) PTKView *paymentView;
@property (strong, nonatomic) IBOutlet UIButton *saveButton;
@end
@implementation V_BuyStripeVC
- (IBAction)saveButtonAction:(UIButton *)sender {
STPCard *card = [[STPCard alloc] init];
//STPToken *token = [[STPToken alloc]init];
card.number = self.paymentView.card.number;
card.expMonth = self.paymentView.card.expMonth;
card.expYear = self.paymentView.card.expYear;
card.cvc = self.paymentView.card.cvc;
[Stripe createTokenWithCard:card completion:^(STPToken *token, NSError *error) {
if (error) {
[self handleError:error];
} else {
[self postStripeToken:token];
}
}];
}
- (void)postStripeToken:(STPToken* )token {
//1
/*
NSURL *postURL = [NSURL URLWithString:STRIPE_TEST_POST_URL];
AFHTTPClient* httpClient = [AFHTTPClient clientWithBaseURL:postURL];
httpClient.parameterEncoding = AFJSONParameterEncoding;
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"text/json"];
*/
//2
// RWCheckoutCart* checkoutCart = [RWCheckoutCart sharedInstance];
NSInteger totalCents = 20000;
//3
NSMutableDictionary* postRequestDictionary = [[NSMutableDictionary alloc] init];
postRequestDictionary[@"stripeAmount"] = [NSString stringWithFormat:@"%d", totalCents];
postRequestDictionary[@"stripeCurrency"] = @"usd";
postRequestDictionary[@"stripeToken"] = token;
postRequestDictionary[@"stripeDescription"] = @"Purchase from FoodApp iOS app!";
//4
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://s547905537.onlinehome.us/ValenX/serverauth.php" parameters:postRequestDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
[self chargeDidSucceed];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self chargeDidNotSuceed];
}];
self.saveButton.enabled = YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
PTKView *view = [[PTKView alloc] initWithFrame:CGRectMake(15,20,290,55)];
self.paymentView = view;
self.paymentView.delegate = self;
[self.view addSubview:self.paymentView];
}
- (void)paymentView:(PTKView *)view withCard:(PTKCard *)card isValid:(BOOL)valid
{
// Toggle navigation, for example
self.saveButton.enabled = valid;
}
- (void)handleError:(NSError *) error {
//1
if ([error.domain isEqualToString:@"StripeDomain"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
//2
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please try again"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
self.saveButton.enabled = YES;
}
- (void)chargeDidSucceed {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Please enjoy your meal."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//Send confirmation email
//RWEmailManager* emailManager = [[RWEmailManager alloc] initWithRecipient:self.nameTextField.text
//recipientEmail:self.emailTextField.text];
//[emailManager sendConfirmationEmail];
//RWCheckoutCart* checkoutCart = [RWCheckoutCart sharedInstance];
//[checkoutCart clearCart];
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)chargeDidNotSuceed {
//2
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Payment not successful"
message:@"Please try again later."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
@end
在过去的 1 周里,我一直坚持这一点。任何帮助表示赞赏。
问候, 阿南德
【问题讨论】:
-
能否将您的项目添加到github并发布链接。
-
我建议你重新格式化你的格式可怕的错误信息。将它放在代码块中应该使其可读。
标签: ios