这是我发现有用的链接
如果我的代码不清楚,请参考它
下面是我用来检查我的 ar-iap 订阅状态的功能代码
进一步阅读下文,了解作为评论找到的每个对应 * 的一些额外信息
func checkForReceipt() {
let receiptUrl = NSBundle.mainBundle().appStoreReceiptURL
let fileExists = NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!)
if fileExists {
let receiptData = NSData(contentsOfURL: receiptUrl!)
let receiptToString = receiptData!.base64EncodedStringWithOptions([])
let dict = ["receipt-data" : receiptToString, "password" : "YOUR SHARED SECRET"] //**
do {
let request = try NSJSONSerialization.dataWithJSONObject(dict, options: []) as NSData!
let storeURL = NSURL(string:"https://sandbox.itunes.apple.com/verifyReceipt")! //***
let storeRequest = NSMutableURLRequest(URL: storeURL)
storeRequest.HTTPMethod = "POST"
storeRequest.HTTPBody = request
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let dataTask = session.dataTaskWithRequest(storeRequest, completionHandler: { (data: NSData?, response: NSURLResponse?, connection: NSError?) -> Void in
do {
let jsonResponse: NSDictionary = try (NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary)!
//****
let expDate: NSDate = self.expirationDateFromResponse(jsonResponse)!
print(expDate)
} catch {
//handle NSJSONSerialization errors
}
})
dataTask.resume()
} catch {
//handle NSJSONSerialization errors
}
} else {
requestReceipt()
}
}
** 您可以从您的 iTunes Connect 帐户获取共享密钥:转到 MyApps >“yourappname”> 功能 > 查看共享密钥 > 生成共享密钥,然后在 dict 的密码字段中插入您生成的密钥
*** 确保在进行生产时将 storeURL 更改为“ https://buy.itunes.apple.com/verifyReceipt ”
**** expireDateFromResponse(jsonResponse: NSDictionary) -> NSDate? 是一个函数,它读取苹果的 json 响应并返回 ar iap 的过期日期