2016-09-14 158 views
3

我如何檢查應用程序購買而不進行實際payment.Do我必須上傳在iTunes上建立檢查應用程序購買。 我在iTunes中創建了產品ID,並且還使用了沙箱用戶進行測試。 但我不知道如何繼續下一步。在應用程序購買實施

回答

3

經過長時間的RnD,我找到了解決方案。 - 第一你必須在輸入所有信息後,在itunes之前創建一個產品ID,在此之前,確保所有的銀行,稅務和賬戶信息填寫協議。 - 你也必須採取屏幕截圖的要求在應用程序購買。 - 後,使在應用程序購買的Xcode功能。 -Import框架 -Import IAPHelper和RageIAPHelper類到你的項目 - 在您的viewcontroller.h類 在IAPHelper.m

添加這些

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]; 
} 

- (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