【问题标题】:MKStoreKit restore purchases always successMKStoreKit 恢复购买总是成功
【发布时间】:2016-01-31 14:55:29
【问题描述】:

我正在尝试制作一个简单的 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购买总是成功。

你有什么想法吗?

【问题讨论】:

  • 你的 IAP 产品是什么类型的?
  • transactionState 属性的值是多少?
  • 这是非消耗性 IPA
  • 你有没有想过这个问题?我在使用自动续订订阅产品时遇到了同样的问题。

标签: ios swift in-app-purchase mkstorekit


【解决方案1】:

您可以使用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")
}

【讨论】:

  • 这是错误的代码,我在第一篇文章中更改了它。它不适用于 MKStoreKitRestoredPurchasesNotification 和 kMKStoreKitRestoringPurchasesFailedNotification
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多