我想使用 appStoreReceiptURL 查看某人购买了哪个版本的应用程序。我怎样才能把它变成一个字符串?
我通过从商店下载应用程序,然后从 Xcode 运行新版本的应用程序来测试这一点。这是我尝试过的:
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");
}
这就是我得到的:
receiptUrl /var/mobile/Applications/E612F261-2D30-416E-BF82-F24xxxx8860/StoreKit/receipt
exists
Error: The operation couldn’t be completed. (Cocoa error 261.)