我正在使用以下代码进行收据验证。
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (!receipt) {
/* No local receipt -- handle the error. */
}
/* ... Send the receipt data to your server ... */
我可以在哪里在我的代码中添加此代码,当我调用它时,每次都会获得不同的收据 ID。任何人请帮助我。
创建一个单独的类文件,并在此类中添加一个方法(或者可以在 AppDelegate.m 文件中编写此方法(
-(void)yourMethodName
{
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (!receipt) {
/* No local receipt -- handle the error. */
}
/* ... Send the receipt data to your server ... */
}
要调用此方法, 从 AppDelegate.m 类中,在要调用的位置编写以下代码。
[[AppDelegate sharedAppdelegate] yourMethodName];
或来自其他类别
[className yourMethodName];
试试这个。