How to use appStoreReceiptURL
Solution 1
This will give you the receipt as the contents of the mainBundle's appStoreReceiptURL :-
[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
Once you get that convert NSData to NSString.
For more details, see this :-
Solution 2
try below:
NSData *dataReceipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSString *receipt = [dataReceipt base64EncodedStringWithOptions:0];
Related videos on Youtube
Janmenjaya
I am having experience in iOS technology. Always intend to learn new things. I have been working as an iOS developer since 2011. An expert in Objective C and currently grasping the knowledge of Swift language. Ready to help the user in SO. Also works as a Freelancer.
Updated on June 06, 2022Comments
-
Janmenjaya almost 2 years
transactionReceipt is deprecated. But I am not able to use,
[[NSBundle mainBundle] appStoreReceiptURL].
This is supposed to return a url to a receipt if there is one. But for me there isn't one, as this value is nil, and as far as I can tell it shouldn't be. I'm running on iOS 7 and have done a few in-app purchases (sandbox on the device).
Can anyone help .
-
Jasarien over 9 yearsthe
appStoreReceiptURL
is a method on an instance of NSBundle, not a class method as you've shown in your question. Are you sure you're calling it on the main bundle as described the documentation?[[NSBundle mainBundle] appStoreReceiptURL]
-
Admin over 9 years@Jasarien, but where would i get this url? If i will get the url from the apple server, will it be automatically saved in the main bundle of the project? Should I directly call "[[NSBundle mainBundle] appStoreReceiptURL]" inside the "updatedTransactions" delegate method? I am sorry, as it may be common question, but i am new here. Can you please elaborate in detail?
-
Jasarien over 9 yearsThe URL will be a file URL to the location of the receipt data within your application's sandbox. If the receipt file is there that method will return you the file URL to it, if it is not there then you won't get any URL.
-
-
quantumpotato almost 7 yearsImportant to use options:0 to avoid \r and \n characters.