【问题标题】:i got error while i open Paypal in iOS 9.0,.but it working on ios 7 and 8我在 iOS 9.0 中打开 Paypal 时出错,但它在 ios 7 和 8 上运行
【发布时间】:2016-04-25 20:16:48
【问题描述】:

当我在 iOS 9 中打开 Paypal for Payment Gateway 时,我的应用程序崩溃了,但它在 iOS 7 和 8 上运行。
如何解决?

由于未捕获的异常“NSRangeException”而终止应用程序,原因: '-[NSTaggedPointerString getCharacters:range:]: Range {0, 7} out of 界限;字符串长度 6'

【问题讨论】:

标签: ios paypal


【解决方案1】:

您是否从 PayPal 开发者网站下载了新框架? 如果是,则使用以下代码:

    self.completedPayment = nil;
    NSMutableArray *items = [[NSMutableArray alloc] init];

    for (Products *product in appDelegate.arrCartItems) {
        PayPalItem *item1 = [PayPalItem itemWithName:product.productName
                                        withQuantity:[product.productSST intValue]
                                           withPrice:[[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%.2f",[product.productSP floatValue]]]
                                        withCurrency:@"USD"
                                             withSku:@"Photos & Videos-00037"];
        //                        NSArray *items = @[item1];
        [items addObject:item1];
    }
    //                float orderPrice = [orderTotal floatValue];
    //                NSLog(@"orderPrice: %f",orderPrice);


    NSDecimalNumber *subtotal = [PayPalItem totalPriceForItems:items];
    // Optional: include payment details
    NSDecimalNumber *shipping = [[NSDecimalNumber alloc] initWithString:@"50.00"];
    NSDecimalNumber *tax = [[NSDecimalNumber alloc] initWithString:@"0.00"];
    PayPalPaymentDetails *paymentDetails = [PayPalPaymentDetails paymentDetailsWithSubtotal:subtotal
                                                                               withShipping:shipping
                                                                                    withTax:tax];

    NSDecimalNumber *totalAmount = [[subtotal decimalNumberByAdding:shipping] decimalNumberByAdding:tax];

    PayPalPayment *payment = [[PayPalPayment alloc] init];
    payment.amount = totalAmount;
    payment.currencyCode = @"USD";
    payment.shortDescription = @"Item Details";
    payment.items = items;  // if not including multiple items, then leave payment.items as nil
    payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil

    if (!payment.processable) {
        // This particular payment will always be processable. If, for
        // example, the amount was negative or the shortDescription was
        // empty, this payment wouldn't be processable, and you'd want
        // to handle that here.
    }

    // Update payPalConfig re accepting credit cards.
    self.payPalConfig.acceptCreditCards = self.acceptCreditCards;

    PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
                                                                                                configuration:self.payPalConfig
                                                                                                     delegate:self];
    [self presentViewController:paymentViewController animated:YES completion:nil];

【讨论】:

  • 我已经尝试过这段代码,但应用仍然在 [self presentViewController:paymentViewController animated:YES completion:nil] 中崩溃;
  • 您可以在这里粘贴错误日志...或您的代码以提供贝宝
  • 我收到以下错误消息-NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array' 但现在我使用 Paypal 2.13.0 仍在工作,但新的 SDK 体积非常大
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-26
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 2015-06-22
  • 1970-01-01
相关资源
最近更新 更多