In application I need to implement auto-renewable subscriptions purchases. As I understand documentation, I should check AppStore receipt on app launch and then validate that receipt with my server. In my code I do following to retrieve receipt:
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
Sometimes receipt
is becoming nil.
For example:
receipt
.receipt
is nil.I do not understand, why this happens. receiptURL
points to file with receipt, but [NSData dataWithContentsOfURL:receiptURL]
returns nil.
If I request receipt refresh, then app shows dialog for entering Itunes credentials. This is not good, because this dialog will appear on app launch and this is unexpected behavior.
Am I doing something wrong? Or maybe this is sandbox-specific case?
In production there will always be a receipt (even if the app is free), that can contain your additional purchase, in case you have bought something or restored from an already purchased item.
In test environment until you buy something the receipt is nil
, if you want to test a case close to production, you should first try a restore (now you will have a receipt) and do what you need.