应用内购买实施

In app purchase Implementation

如何在不进行实际操作的情况下检查应用内购买 payment.Do 我必须在 iTunes 上上传构建以检查应用内购买。 我在 iTunes 中创建了产品 ID,还创建了一个沙箱用户来测试。 但是我不知道下一步该怎么做。

经过长时间的研发,我找到了解决方案。 -首先您必须在输入所有信息后在 iTunes 中创建一个产品 ID,在此之前确保所有银行、税务和帐户信息均按协议填写。 -您 还必须截取要求进行应用内购买的屏幕截图。 -After 在 xcode 功能中启用应用内购买。 -导入框架 - 将 IAPHelper 和 RageIAPHelper class 导入您的项目 -在你的 viewcontroller.h class 添加这些

NSArray *_products;
NSNumberFormatter * _priceFormatter;

-(void)viewdidload
{
 [self reload];
    [[RageIAPHelper sharedInstance] restoreCompletedTransactions];
    _priceFormatter = [[NSNumberFormatter alloc] init];
    [_priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
}

- (void)restoreTapped:(id)sender {
    [[RageIAPHelper sharedInstance] restoreCompletedTransactions];
}

- (void)productPurchased:(NSNotification *)notification {

    NSString * productIdentifier = notification.object;
    [_products enumerateObjectsUsingBlock:^(SKProduct * product, NSUInteger idx, BOOL *stop) {
        if ([product.productIdentifier isEqualToString:productIdentifier]) {
            *stop = YES;
      NSLog(@" productPurchased");

}
- (void)reload {
    _products = nil;

    [[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
        if (success) {
            _products = products;

        }

    }];
}

- (void)buyButtonTapped {


    SKProduct *product = _products[0];

    NSLog(@"Buying %@...", product.productIdentifier);
    if(product!=nil)
    {
    [[RageIAPHelper sharedInstance] buyProduct:product];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Your In-App Purchase"
                                                        message:@"Subscription is required to access thi sfeature."
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Buy", nil];
        [alert show];

    }

}
-(void)viewwillappear
{
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil];
}

在IAPHelper.m

- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {
 if ([productIdentifier isEqualToString:@"com.abc.productName"]) {

        int currentValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"com.abc.productName"];
}

此处将 "com.abc.productName" 替换为您创建的产品 ID。 这都在代码部分 要测试应用程序内购买 - 在 phone 设置中注销现有的苹果 ID,然后使用您从 iTunes 创建的沙盒用户登录。 然后不用实际付款就可以查看了。

要下载 IAPHelper class 并参考文档:https://github.com/saturngod/IAPHelper