Kaynağa Gözat

Update README for completeTransactions

Andrea Bizzotto 7 yıl önce
ebeveyn
işleme
e22e7b1ee4
1 değiştirilmiş dosya ile 15 ekleme ve 11 silme
  1. 15 11
      README.md

+ 15 - 11
README.md

@@ -35,17 +35,21 @@ SwiftyStoreKit supports this by calling `completeTransactions()` when the app st
 
 ```swift
 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
-    SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
-        for purchase in purchases {
-            if purchase.transaction.transactionState == .purchased || purchase.transaction.transactionState == .restored {
-                if purchase.needsFinishTransaction {
-                    // Deliver content from server, then:
-                    SwiftyStoreKit.finishTransaction(purchase.transaction)
-                }
-                print("purchased: \(purchase)")
-            }
-        }
-    }
+	// see notes below for the meaning of Atomic / Non-Atomic
+	SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
+	    for purchase in purchases {
+	        switch purchase.transaction.transactionState {
+	        case .purchased, .restored:
+	            if purchase.needsFinishTransaction {
+	                // Deliver content from server, then:
+	                SwiftyStoreKit.finishTransaction(purchase.transaction)
+	            }
+	            // Unlock content
+	        case .failed, .purchasing, .deferred:
+	            break // do nothing
+	        }
+	    }
+	}
     return true
 }
 ```