【问题标题】:"lldb" Error When Testing In-App Purchase测试应用内购买时出现“lldb”错误
【发布时间】:2015-02-01 01:58:04
【问题描述】:

请耐心等待。这是我第一次设置应用内购买,我会尽力提供尽可能多的信息。我最终没有为其他人的代码整理互联网,而是购买了一个无限技能课程,专门介绍如何将非续订订阅应用内购买添加到我的应用程序。他们的课已经过时了,后来发现,“跟随”项目文件没有下载。所以我做了很多研究,这就是我想出的:

  1. 我在 iTunes 中创建了一个应用内购买,应用内标识符与我的 .m 编码中的标识符匹配。

  2. 我创建了一个新的配置文件并启用了应用内购买和 icloud 来管理购买的后端。当我返回应用程序时,我启用了 icloud 并确保在项目目标中打开了应用程序内购买。

  3. 我创建了一个视图控制器,添加了按钮,并为子类使用了 SKStoreProductViewController。该视图控制器如下所示:

  4. 我导入了 storekit 和 SK 代表。

当我从主视图中点击标签栏按钮以将我带到应用内视图控制器时,它会崩溃。

最后是编码: InAppViewController.h:

#import <StoreKit/StoreKit.h>

@interface InAppViewController : SKStoreProductViewController

@end

InAppViewController.m:

//
//  InAppViewController.m
//  Contractor Rich
//
//  Created by Joshua Hart on 2/1/15.
//  Copyright (c) 2015 Code By Hart. All rights reserved.
//

#import "InAppViewController.h"
#import <StoreKit/StoreKit.h>

@interface InAppViewController ()<SKProductsRequestDelegate, SKPaymentTransactionObserver>

@property (weak, nonatomic) IBOutlet UIButton *btnBuyAccess;
@property (weak, nonatomic) IBOutlet UIButton *btnPremiumFeature;
@property (weak, nonatomic) IBOutlet UILabel *lblStatus;

@property (strong, nonatomic) SKProduct *product;
@property (strong, nonatomic) NSUbiquitousKeyValueStore *keyStore;
@property (strong, nonatomic) NSDate *expirationDate;

- (IBAction)btnBuyAccessTouched: (id)sender;

-(void)getProductInfo;


@end

@implementation InAppViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _btnBuyAccess.userInteractionEnabled = NO;

    _keyStore = [[NSUbiquitousKeyValueStore alloc] init];




    _expirationDate = [_keyStore objectForKey:@"expirationDate"];
    NSDate *today = [NSDate date];
    if (_expirationDate == nil)
        _expirationDate = today;

    if (_expirationDate > today) {
        _btnPremiumFeature.userInteractionEnabled = YES;
    }
        else {
            _btnBuyAccess.userInteractionEnabled = YES;

            [self getProductInfo];
        }
    }

-(void) getProductInfo{

    if ([SKPaymentQueue canMakePayments])
    {
        NSMutableArray *productIdentifierList = [[NSMutableArray alloc] init];

        [productIdentifierList addObject:[NSString stringWithFormat:@"com.joshua.contractorrich.inapp"]];

                                          SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithArray:productIdentifierList]];

        request.delegate = self;
        [request start];
    }
}

-(void) productsRequest: (SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    NSArray *products = response.products;

    if (products.count != 0)
    {
        _product = products[0];
        _btnBuyAccess.userInteractionEnabled = YES;
        _lblStatus.text = @"Ready for Purchase!";
    }else{
        _lblStatus.text = @"Product was not Found!";
    }
    products = response.invalidProductIdentifiers;
    for (SKProduct *product in products)
    {
        NSLog(@"Product not found: %@", product);
    }

}



- (IBAction)btnBuyAccessTouched: (id)sender {

    SKPayment *payment = [SKPayment paymentWithProduct:_product];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchased:
                _btnPremiumFeature.userInteractionEnabled = YES;
                _lblStatus.text = @"Purchase Completed!";
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;

            case SKPaymentTransactionStateFailed: NSLog(@"Transaction Failed!");
                _lblStatus.text = @"Purchase Failed!";
                [[SKPaymentQueue defaultQueue]
            finishTransaction:transaction];

            default:
                break;
        }
    }
}

-(void) setExpirationDate {
    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setMonth:3];
    NSDate *expirationDate = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:[NSDate date] options:0];
    [_keyStore setObject:expirationDate forKey:@"expirationDate"];
    [_keyStore synchronize];
}

-(void) initializeStore {
    [_keyStore setObject:nil forKey:@"expirationDate"];
    [_keyStore synchronize];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

请理解这是我第一次尝试这个。对我来说,可能看起来很愚蠢的仍然是学习阶段。谢谢!

【问题讨论】:

  • 什么是CUICatalog?这就是错误消息的来源。
  • 这是一个我找不到的 ui 图像,这在某处引起了一些头痛,这是一个我已经有一段时间无法修复的错误。即使在调试器中显示,应用程序也运行良好。绝对不会影响应用内运行时错误。
  • 但这是您遇到的唯一问题。如果这不是问题,你有什么问题?我在您的屏幕截图中没有看到其他“运行时错误”。

标签: ios objective-c testing in-app-purchase runtime-error


【解决方案1】:

这个故事中没有运行时错误。所发生的只是您创建了一个异常断点。现在你停下来了。只需恢复运行。如果这很麻烦,请禁用 Exceptions 断点。

【讨论】:

  • 你是对的,但是现在当我尝试运行它时,我收到错误:'InAppViewController must be used in a modal view controller',然后以未捕获的 NSException 终止...
  • "现在当我尝试运行它时,我收到错误" 对,但我相信你现在意识到,这就是重点。您需要越过断点以找出异常
  • 我现在没有收到任何错误,但是我的 IAP 视图控制器显示完全黑屏,没有错误,这可能是什么原因?
  • 通常是因为视图控制器无法找到包含其视图的 nib。它的视图是否在 nib(.xib 文件)中?如果这是问题所在,请在此处查看我的讨论:stackoverflow.com/a/25539016/341994
  • 如果这不是问题,我想知道您是否正确忽略“无法加载图像”错误。
猜你喜欢
  • 1970-01-01
  • 2011-10-02
  • 1970-01-01
  • 1970-01-01
  • 2012-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多