I want to use appStoreReceiptURL to see which version of the app someone purchased. How can I get this into a string?
I'm testing this by downloading the app from the store, then running a new version of the app from Xcode. Here is what I've tried:
NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(@"receiptUrl %@",[receiptUrl path]);
if ([[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]]) {
NSLog(@"exists");
NSError *error;
NSString *receiptString = [[NSString alloc] initWithContentsOfFile:[receiptUrl path] encoding:NSUTF8StringEncoding error:&error];
if (receiptString == nil) {
NSLog(@"Error: %@", [error localizedDescription]);
} else {
NSLog(@"Receipt: %@",receiptString);
}
} else {
NSLog(@"does not exist");
}
This is what I get:
receiptUrl /var/mobile/Applications/E612F261-2D30-416E-BF82-F24xxxx8860/StoreKit/receipt
exists
Error: The operation couldn’t be completed. (Cocoa error 261.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…