我正在开发非耗材的IAP功能(删除广告)。 我为所有操作创建了一个帮手,一切正常。
当用户购买/恢复购买时,我将其设置为:
let save = UserDefaults.standard
save.set(true, forKey: "Purchase")
save.synchronize()
只要用户永远不会删除该应用,这就可以正常工作。
我想知道...... 有没有办法知道用户(删除并重新安装应用程序后)是否已经购买?所以更改按钮的标题来自"购买"到"恢复"?
答案 0 :(得分:0)
如果您提供登录系统,您将很容易知道,否则
您不应该为付款设置购买和恢复按钮,也不能存储此键值 设备密钥链并在首次设置中读取它们,但您应该从 ios 10.3 了解如果您删除了相应的密钥链项目将被删除
注意:Apple 声明所有拥有IAP的应用都应该提供还原支付功能,如果有解决方法应用将被 Apple
拒绝答案 1 :(得分:0)
对于每个应用,Apple都要求您包含“还原购买”按钮。这正是您面临的问题。它将为以前购买的每个IAP重新创建session_start();
include("include/session.php");
if(!$session->logged_in){
header("Location: Login.php");
}
,并为当前在App Store登录的iCloud帐户恢复“已恢复”状态,并将其放在function startSession()
{
global $database; //The database connection
session_start(); //Tell PHP to start the session
/* Determine if user is logged in */
$this->logged_in = $this->checkLogin();
/**
* Set guest value to users not logged in, and update
* active guests table accordingly.
*/
if(!$this->logged_in) {
$this->username = $_SESSION['username'] = GUEST_NAME;
$this->userlevel = GUEST_LEVEL;
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
} else { /* Update users last active timestamp */
$database->addActiveUser($this->username, $this->time);
}
/* Remove inactive visitors from database */
$database->removeInactiveUsers();
$database->removeInactiveGuests();
/* Set referrer page */
if(isset($_SESSION['url'])) {
$this->referrer = $_SESSION['url'];
} else {
$this->referrer = "/";
}
/* Set current url */
$this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
}
上。 Read more...
答案 2 :(得分:0)
当用户在您的应用中进行互动时,也许在您的代码中进行收据验证是有意义的。 (Apple文档:https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Introduction.html)
看看这个小例子:
初始化您的产品请求:
if SKPaymentQueue.canMakePayments() {
print("starting IAPS")
let productIdentifiers = Set(["YOUR_IAPP_IDENTIFIER#1", "YOUR_IAPP_IDENTIFIER#1"])
let request = SKProductsRequest(productIdentifiers: productIdentifiers as Set<String>)
request.delegate = self
request.start()
} else {
print("please enable IAPS")
}
在您的应用中设置您的产品并进行收据验证
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
print("product request")
let myProduct = response.products
for product in myProduct {
if product.productIdentifier == "YOUR_IAPP_IDENTIFIER#1" {
self.productYear = product
} else if product.productIdentifier == "YOUR_IAPP_IDENTIFIER#2" {
self.productMonth = product
}
print("product added")
print(product.productIdentifier)
print(product.localizedTitle)
print(product.localizedDescription)
print(product.price)
self.receiptValidation()
}
验证示例
func receiptValidation() {
self.logger.log.debug("In receipt validation")
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
do {
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
let receiptString = receiptData.base64EncodedString(options: [])
let dict = ["receipt-data" : receiptString, "password" : "YOUR_PASSWORD"] as [String : Any]
// Getting the receipt data from the JSON file and other logic
// ...
// ...
}
}
}
如果您需要进一步澄清,请告诉我。此外,您只需使用PaymentQueue(Apple Doc:https://developer.apple.com/documentation/storekit/skpaymentqueue)
即可恢复它