I am creating a sample app for in app purchase. I have implemented for one product I used the following code in which I can implement the for one product purchasing, but if suppose there are more than one product then how can I get the list of all the identifiers for all the products available. Hope I am clear with the question.
I have used the following code for for one product as below.
- (void)viewDidLoad {
[super viewDidLoad];
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"Parental-controls are disabled");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.companion.onemonth"]];
productsRequest.delegate = self;
[productsRequest start];
} else {
NSLog(@"Parental-controls are enabled");
//com.companion.onemonth ;
}
}
- (IBAction)purchase {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.companion.onemonth"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
Through this code I can get for one product but dont know how to get multiple identifiers at run time.
Put all your defined products hardcoded into the NSSet of SKProductsRequest:
[NSSet setWithObjecta:@"com.companion.onemonth", @"com.companion.twomonth"], nil)and you you get an NSArray of available products in the delegate method:
SKProductsResponse will have an array of your products.