MKStoreKit恢复购买总是成功

时间:2016-01-31 14:55:30

标签: ios swift in-app-purchase mkstorekit

我试图制作一个简单的IAP来删除我应用的所有广告。 当我购买IAP时,它可以正常工作,但是当我尝试使用明确的沙盒帐户(从未购买过IAP)进行restore购买时,它可以正常工作。

因此,restorePurchases()始终有效,即使用户之前没有购买过IAP。

有我的代码: 当用户选择恢复按钮时,我执行以下方法:

func restaureIAP() {
    PKNotification.toast("Chargement en cours...")
    MKStoreKit.sharedKit().restorePurchases()
}

我还添加了观察者:

// Product restaure
        NSNotificationCenter.defaultCenter().addObserverForName(kMKStoreKitRestoredPurchasesNotification,
            object: nil, queue: NSOperationQueue.mainQueue()) { (note) -> Void in
                PKNotification.success("Restauré !")
                print ("Succes restaure: \(note.object)")

                NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isPurchase")
        }

        NSNotificationCenter.defaultCenter().addObserverForName(kMKStoreKitRestoringPurchasesFailedNotification,
            object: nil, queue: NSOperationQueue.mainQueue()) { (note) -> Void in
                PKNotification.failed("Erreur")
                print ("Failed restaure: \(note.object)")
        }

这个应用程序在AppStore上提供,并且存在同样的问题:购买IAP工作但restore购买总是成功。

你有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用MKStoreKitRestoredPurchasesNotificationkMKStoreKitRestoringPurchasesFailedNotification观察员查看已恢复的交易。

 MKStoreKit.sharedKit().startProductRequest()
 NSNotificationCenter.defaultCenter().addObserverForName(kMKStoreKitRestoredPurchasesNotification,
  object: nil, queue: NSOperationQueue.mainQueue()) { (note) -> Void in
    print ("Restored product: \(note.object)")
}

 NSNotificationCenter.defaultCenter().addObserverForName(kMKStoreKitRestoringPurchasesFailedNotification,
  object: nil, queue: NSOperationQueue.mainQueue()) { (note) -> Void in
    print ("Restored failed")
}
相关问题