Question

I've been trying to make in-app purchase work. Currently I've an application (Version 1.1) in app store. I want to release another version (V 1.2) in that version I want to integrate in app purchase. I've created a product for that. But when I try to load all product then it shows there is no product.

V1.2 is in the form of ready to upload binary. I've associated in app purchase. I just want to test in App Purchase. I've deleted all the provisioning profile from my devices (MAC + iPhone). Currently I've only one profile installed.

Here is my code:

-(void)fetchAvailableProducts{
    NSSet *productIdentifiers = [NSSet
                                 setWithObjects:bundle_identifier,nil];
    productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
    productsRequest.delegate = self;
    [productsRequest start];
}

- (void)requestDidFinish:(SKRequest *)request {
    NSLog(@"purchase request finished");
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"%@", [error description]);
}

- (BOOL)canMakePurchases
{
    return [SKPaymentQueue canMakePayments];
}
- (void)purchaseMyProduct:(SKProduct*)product{
    if ([self canMakePurchases]) {
        SKPayment *payment = [SKPayment paymentWithProduct:product];
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    else{
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                  @"Purchases are disabled in your device" message:nil delegate:
                                  self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alertView show];
    }
}

#pragma mark StoreKit Delegate

-(void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Purchasing");
                break;
            case SKPaymentTransactionStatePurchased:
                if ([transaction.payment.productIdentifier
                     isEqualToString:bundle_identifier]) {
                    NSLog(@"Purchased ");
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                              @"Purchase is completed succesfully" message:nil delegate:
                                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alertView show];
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"Restored ");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                NSLog(@"Purchase failed ");
                break;
            default:
                break;
        }
    }
}

-(void)productsRequest:(SKProductsRequest *)request
    didReceiveResponse:(SKProductsResponse *)response
{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    NSLog(@"%@",response.products);
    if (count>0) {
        validProducts = response.products;
        validProduct = [response.products objectAtIndex:0];
        if ([validProduct.productIdentifier
             isEqualToString:bundle_identifier]) {
        }
    } else {
        UIAlertView *tmp = [[UIAlertView alloc]
                            initWithTitle:@"Not Available"
                            message:@"No products to purchase"
                            delegate:self
                            cancelButtonTitle:nil
                            otherButtonTitles:@"Ok", nil];
        [tmp show];
    }
}

I wanted to know what is the correct procedure for enabling in-app purchase and what I am doing wrong? And what should be done?

Was it helpful?

Solution

I solved the problem, so I am adding this as answer.

I mixed up with bundle identifier and product identifier. My code was correct, I provided bundle identifier instead of product identifier, this is the reason that I was not getting any products.

NSSet *productIdentifiers = [NSSet
                                 setWithObjects:product_identifier,nil];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];

In the above code use product_identifier(s). as I've only one product created so I am using single element to construct the set.

OTHER TIPS

Your code looks correct. Have you confirmed that your in-app product id matches exactly the value in the bundle_id variable?

 + (RageIAPHelper *)sharedInstance {
static dispatch_once_t once;
static RageIAPHelper * sharedInstance;
dispatch_once(&once, ^{
    NSSet * productIdentifiers = [NSSet       setWithObject:kMDPulseSubscriptionProductIdentifier];
    sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
});
return sharedInstance;
   }

You get the products list, but you have to test it on real device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top