Ali*_*yan 28 iphone objective-c in-app-purchase ios7
我正在使用此代码进行应用内购买,从RaywernderLich的教程中获取.
// Encode the receiptData for the itms receipt verification POST request.
NSString *jsonObjectString = [self encodeBase64:(uint8_t *)transaction.transactionReceipt.bytes
length:transaction.transactionReceipt.length];
Run Code Online (Sandbox Code Playgroud)
现在Xcode说
不推荐使用'transactionReceipt':首先在iOS 7.0中弃用
怎么解决?
Dan*_*sko 20
由于这个问题在技术上询问人们应如何解决已弃用的属性,因此可以假设OP仍在部署在小于7的iOS版本上.因此,您需要检查新API的可用性,而不是盲目地调用它:
编辑 正如评论中指出的那样,您无法在NSBundle上使用respondsToSelector,因为该API在之前的iOS版本中是私有的
NSData *receiptData;
if (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_7_0) {
receiptData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
} else {
receiptData = transaction.transactionReceipt;
}
//now you can convert receiptData into string using whichever encoding:)
Run Code Online (Sandbox Code Playgroud)
由于Swift只能部署在iOS 7及更高版本上,我们可以appStoreReceiptURL安全地使用
if let receiptData = NSData(contentsOfURL: NSBundle.mainBundle().appStoreReceiptURL!) {
//we have a receipt
}
Run Code Online (Sandbox Code Playgroud)
收据现在包含的新API包含用户执行的所有交易的列表.该文件清楚地概述了收据的样子:

这意味着如果您真的真的想要,您可以遍历收据中包含的所有项目以验证每个事务.
有关收据验证的更多信息,请阅读obc.io
Nik*_* M. 16
替换为:
[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
Run Code Online (Sandbox Code Playgroud)
之后转换NSData为NSString......
Phi*_*hil 10
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if(!receipt) {
/* No local receipt -- handle the error. */
}
NSString *jsonObjectString = [receipt base64EncodedString];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12669 次 |
| 最近记录: |