From 611b091dfe3a90326a7e73a675ed6f8ac7b5bc29 Mon Sep 17 00:00:00 2001 From: Tenfay Date: Mon, 11 Nov 2024 13:19:17 +0800 Subject: [PATCH] Update README-en.md --- README-en.md | 99 ++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/README-en.md b/README-en.md index bbc7881..fc4ed0f 100644 --- a/README-en.md +++ b/README-en.md @@ -48,7 +48,7 @@ pod 'DYFStore' Or ``` -pod 'DYFStore', '~> 2.2.0' +pod 'DYFStore', '~> 2.3.0' ``` Check out the [wiki](https://github.com/itenfay/DYFStore/wiki/Installation) for more options. @@ -95,18 +95,19 @@ You can process the purchase which was initiated by user from the App Store and ``` // Processes the purchase which was initiated by user from the App Store. -func didReceiveAppStorePurchaseRequest(_ queue: SKPaymentQueue, payment: SKPayment, forProduct product: SKProduct) { +func didReceiveAppStorePurchaseRequest(_ queue: SKPaymentQueue, payment: SKPayment, forProduct product: SKProduct) -> Bool { if !DYFStore.canMakePayments() { self.sk_showTipsMessage("Your device is not able or allowed to make payments!") - return + return false } // Get account name from your own user system. let accountName = "Handsome Jon" // This algorithm is negotiated with server developer. - let userIdentifier = DYFStoreCryptoSHA256(accountName) ?? "" + let userIdentifier = accountName.tx_sha256 ?? "" DYFStoreLog("userIdentifier: \(userIdentifier)") SKIAPManager.shared.addPayment(product.productIdentifier, userIdentifier: userIdentifier) + return true } ``` @@ -155,7 +156,7 @@ private func addPayment(_ productId: String) { // Get account name from your own user system. let accountName = "Handsome Jon" // This algorithm is negotiated with server developer. - let userIdentifier = DYFStoreCryptoSHA256(accountName) ?? "" + let userIdentifier = accountName.tx_sha256 ?? "" DYFStoreLog("userIdentifier: \(userIdentifier)") SKIAPManager.shared.addPayment(productId, userIdentifier: userIdentifier) } @@ -238,34 +239,40 @@ If you need an opaque identifier for the user’s account on your system to add Calculates the SHA256 hash function: ``` -public func DYFStoreCryptoSHA256(_ s: String) -> String? { - guard let cStr = s.cString(using: String.Encoding.utf8) else { - return nil - } - let digestLength = Int(CC_SHA256_DIGEST_LENGTH) // 32 - let cStrLen = Int(s.lengthOfBytes(using: String.Encoding.utf8)) - - // Confirm that the length of C string is small enough - // to be recast when calling the hash function. - if cStrLen > UINT32_MAX { - print("C string too long to hash: \(s)") - return nil - } - - let md = UnsafeMutablePointer.allocate(capacity: digestLength) - CC_SHA256(cStr, CC_LONG(cStrLen), md) - // Convert the array of bytes into a string showing its hex represention. - let hash = NSMutableString() - for i in 0.. UINT32_MAX { + print("C string too long to hash: \(self)") + return nil + } + + let md = UnsafeMutablePointer.allocate(capacity: digestLength) + CC_SHA256(cStr, CC_LONG(cStrLen), md) + // Convert the array of bytes into a string showing its hex represention. + let hash = NSMutableString() + for i in 0..