You do not need to show the price. Apple will do that before the user makes a purchase. But if you have multiple IAPs on the store (e.g. 10 widgets, 100 widgets or a 1 month subscription or a 6 month subscription) you might want to. Here is code in Objective C:
Code Block NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; |
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; |
[numberFormatter setLocale:[[response.products objectAtIndex:0] priceLocale]]; |
UIAlertController *alert = |
[UIAlertController alertControllerWithTitle:@"IAP Products" message:@"The following packages are available for purchase. DESCRIBE PACKAGES GENERICALLY \nPlease select a package." preferredStyle:UIAlertControllerStyleAlert]; |
for(int iCount=0;iCount<[response.products count];iCount++){ |
[alert addAction:[UIAlertAction actionWithTitle:[[[response.products objectAtIndex:iCount] localizedDescription] stringByAppendingFormat:@" %@",[numberFormatter stringFromNumber:[[response.products objectAtIndex:iCount] price]]] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { |
[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; |
SKPayment *paymentRequest= [SKPayment paymentWithProduct:[response.products objectAtIndex:iCount]]; |
[[SKPaymentQueue defaultQueue] addPayment:paymentRequest]; |
}]]; |
} |
|
[alert addAction:[UIAlertAction actionWithTitle:@"Check for recent purchase" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { |
[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; |
[self performSelector:@selector(endIAP) withObject:nil afterDelay:5.0f]; |
comment - endIAP uses status to issue an alert - also in updatedTransactions add a cancelPreviousPerformRequestsWithTarget: |
|
self->status=@"no approved purchase"; |
}]]; |
|
[alert addAction:[UIAlertAction actionWithTitle:@"Not now, maybe later" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { |
self->status=@"not now"; |
[self endIAP]; |
comment - endIAP uses status to issue an alert |
}]]; |
|
[self presentThisAlert:alert]; |
comment - presentThisAlert issues an alert |