在应用购买执行中



如何在没有实际付款的情况下检查应用内购买。我是否必须在iTunes上上传构建以检查应用程序购买。我在iTunes中创建了产品Id,并创建了一个沙盒用户进行测试。但是我不知道下一步该怎么做。

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

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 。这些都在代码部分要测试应用内购买功能,请在手机设置中退出现有的apple id,并使用从itunes创建的沙箱用户登录。然后你可以在不实际付款的情况下检查。

下载IAPHelper类和文档,请参阅:https://github.com/saturngod/IAPHelper

相关内容

最新更新