
1.下面是我自己畫的一個大概的流程圖(字比較爛,將就這看吧哈~)

圖中 ① 為請求商品詳情之後根據商品的ID 發起支付請求 (這裡的Id 就是商品的ProductId)



然後是圖中② 在收到蘋果返回的支付結果後做的處理

這裡會收到蘋果支付的返回憑證,這裡要做下本地儲存,防止傳送後臺失敗引起的丟單。


2.丟單產生的情況和處理
1.在①的時候重點是在封裝的時候把訂單資訊寫進SKMutablePayment,這樣在收到支付結果的時候就可以去取出這個訂單號,傳送後臺進行驗證,這樣就能有效的規避串單問題。 2.在②的時候在使用者支付之後還未收到憑證回撥之後如果app 出現異常,就不能正常接收支付結果的回撥,這個時候,只要不主動關閉這次交易事務下次設定監聽的時候(建議重啟的時候),還是可以獲取到這次交易回撥,再進行憑證處理。
MyStoreObserver *tempObserver = [MyStoreObserver shareInstance];
self.observer = tempObserver;
[[SKPaymentQueue defaultQueue] addTransactionObserver:tempObserver];
複製程式碼
3.在③的時候收到憑證的回撥之後傳送後臺驗證這塊很可能會出現傳送失敗等情況,這個時候就要把憑證進行本地儲存(儲存的是記得是儲存為陣列,因為可能有多個),在驗證成功之後再刪除本地儲存的憑證。
丟單的處理在上面的貼圖程式碼中也有體現,希望對你會有幫助,大體總結就到這裡了,中午吃飯了,就這麼多吧! ?