【发布时间】:2013-12-13 22:03:06
【问题描述】:
我正在尝试将 Paypal SDK 实施到我的 iOS 应用中。我完全从自述文件说明中复制了代码,导入了文件,并将我的按钮链接到我的操作,但是当我单击该按钮时,它给了我一个“线程 1 信号:SIGABRT”错误并崩溃。
这是我的 .m 文件中的 Paypal 代码:
- (IBAction)pay {
// Create a PayPalPayment
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:@"39.95"];
payment.currencyCode = @"USD";
payment.shortDescription = @"Product";
// Check whether payment is processable.
if (!payment.processable) {
// If, for example, the amount was negative or the shortDescription was empty, then
// this payment would not be processable. You would want to handle that here.
}
// Provide a payerId that uniquely identifies a user within the scope of your system,
// such as an email address or user ID.
NSString *aPayerId = @"someone@someone.com";
// Create a PayPalPaymentViewController with the credentials and payerId, the PayPalPayment
// from the previous step, and a PayPalPaymentDelegate to handle the results.
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc] initWithClientId:@"MY-CLIENT-ID-HERE"
receiverEmail:@"MY-EMAIL-HERE"
payerId:aPayerId
payment:payment
delegate:self];
// Present the PayPalPaymentViewController.
[self presentViewController:paymentViewController animated:YES completion:nil];
}
#pragma mark - PayPalPaymentDelegate methods
- (void)payPalPaymentDidComplete:(PayPalPayment *)completedPayment {
// Payment was processed successfully; send to server for verification and fulfillment.
[self verifyCompletedPayment:completedPayment];
// Dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel {
// The payment was canceled; dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
// Send the entire confirmation dictionary
NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation
options:0
error:nil];
// Send confirmation to your server; your server should verify the proof of payment
// and give the user their goods or services. If the server is not reachable, save
// the confirmation and try again later.
}
有人知道问题可能是什么吗?
【问题讨论】:
-
尝试在
pay方法中定位崩溃发生的位置。我会通过系统地注释掉代码的各个部分来做到这一点。我将首先注释掉presentViewController:animated:completion:行。看看是视图控制器导致了崩溃还是其他原因,然后回复我们。 -
当我删除该行并点击按钮时,它不会崩溃,但它不会做任何事情,只是停留在那个屏幕上。
-
我不知道 SDK,所以希望其他人能够帮助你。我为你的知名度投了赞成票。与此同时,这就是我要做的。我快速浏览了 SDK。看起来您已经正确设置了代码,但除了代码之外还有很多设置步骤。如果您还没有,我将使用清单验证项目设置的每个部分。你可能错过了什么。祝你好运! SDK:
https://github.com/paypal/PayPal-iOS-SDK -
谢谢你的帮助!
-
我就这个问题联系了 Paypal,他们查看了我的控制台日志并说这与 Google Analytics(分析)有关,你知道这两者有什么会导致问题吗?
标签: ios objective-c paypal sigabrt