首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKStoreKit恢复采购总是成功的

MKStoreKit恢复采购总是成功的
EN

Stack Overflow用户
提问于 2016-01-31 14:55:29
回答 1查看 542关注 0票数 0

我试图做一个简单的IAP删除我的应用程序的所有广告。当我购买IAP时,它可以工作,但是当我尝试使用restore使用明确的沙箱帐户(它从来没有购买IAP)时,它就能工作。

因此,restorePurchases()总是有效的,即使用户以前没有购买IAP。

这是我的代码:当用户选择还原按钮时,我执行以下方法:

代码语言:javascript
复制
func restaureIAP() {
    PKNotification.toast("Chargement en cours...")
    MKStoreKit.sharedKit().restorePurchases()
}

我还增加了观察员:

代码语言:javascript
复制
// 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购买总是成功的。

你有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-01 11:40:59

您可以使用MKStoreKitRestoredPurchasesNotificationkMKStoreKitRestoringPurchasesFailedNotification观察者检查还原的事务。

代码语言:javascript
复制
 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")
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35115207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档