在iOS中进行应用购买测试 [英] In app purchase testing in iOS

查看:148
本文介绍了在iOS中进行应用购买测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Xcode 8.0,Swift 3.0 并在我的iPad上测试应用内购买。 我想使用沙盒用户测试应用内购买。

I am using Xcode 8.0, Swift 3.0 and testing in app purchases in my iPad. I want to test in app purchases using sandbox user.

设备的设置中没有添加帐户

问题是我没有得到产品列表以响应产品请求代码。
请查看我的代码:

The Problem is I am not getting product list in response of product request code. Please take a look on my code:

let PRODUCT_ID_MY_PRODUCT = "com.company.ProjectName.MyProduct"
// The ProducID in this code and ProducID on iTunes are the SAME. ✔️

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if productID == nil {
        productID = PRODUCT_ID_MY_PRODUCT
    }
    SKPaymentQueue.default().add(self)
}


override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    startPurchases()
}

func startPurchases() {
    if (SKPaymentQueue.canMakePayments())
    {
        let productIDs = NSSet(object: self.productID!)

        let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productIDs as! Set<String>)
        productsRequest.delegate = self
        productsRequest.start()
    }
}


// Delegate Methods for SKProductsRequest
func productsRequest (_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
    let count : Int = response.products.count
       // THE PROBLEM IS HERE.. I AM GETTING COUNT IS ZERO.. MEANS response.products returning null ARRAY
    if (count>0) {
        let validProducts = response.products
        for aProduct in validProducts {
            print(aProduct.productIdentifier)
        }
    } else {
        DispatchQueue.main.async(execute: {
            UIAlertView(title: "Purchase !", message: "Product not available", delegate: nil, cancelButtonTitle: "OK").show()
            return
        })
    }
}

所以.....这就是问题:我收到了response.products null(数组中没有数据)所以请帮帮我找到解决方案。您可以在代码中看到评论:
//问题在这里..我的计数是零。意味着response.products返回null ARRAY

So..... That's the problem: I am getting response.products null (no data in array) so Please help me to find the solution. You can see the comments in code: // THE PROBLEM IS HERE.. I AM GETTING COUNT IS ZERO.. MEANS response.products returning null ARRAY

我通过iTunes Connect创建了产品。你可以看到下面的图片。所有产品都处于准备提交状态。

I created products over iTunes Connect. You can see the image below. All the products are in "Ready to Submit" state.

iTunes上有一些警告

There is some warning on iTunes

Your first In-App Purchase must be submitted with a new app version. 
Select it from the app’s In-App Purchases section and click Submit.


Once your binary has been uploaded and your first In-App Purchase 
has been submitted for review, additional In-App Purchases can be 
submitted using the table below.

我还创建了 Sendbox用户进行测试应用内购买。见下图:

I also created Sendbox user for testing In-App Purchases. See the image below:

我错过了什么吗?或者错误是什么?错误在哪里? 我想使用沙盒用户测试应用内购买

Did I miss something? Or what is the error? And where is error? I want to test in app purchases using sandbox user

推荐答案

我修复此问题。有一点需要注意。见下文:

I fixed this. There are some points need to careful about. See below:


  • 确保您的开发者帐户签订了付费应用程序合同。请参阅以下图片:

  • 在iTunes Connect上创建产品。

  • 实施应用内购买代码和配置设置。

  • 使用分发配置文件创建一个版本。

  • 在商店上传构建。将构建添加到当前版本。将应用程序内购买添加到iTunes Connect上的版本。

  • 然后尝试测试,如果仍然没有,则提交应用程序一次然后取消它。然后尝试在您的设备上进行测试。

  • 确保在使用沙盒用户进行测试时,您需要从设备设置中注册已登录的帐户,然后使用沙箱ID登录。

  • 一些截图可能会有所帮助。

  • Make sure your developer account did the paid application contract. see image below:
  • Create Products on the iTunes Connect.
  • Implement In-App-Purchases code and configuration settings.
  • Create one build with Distribution profile.
  • Upload build on store. Add build to current version. Add In-App-Purchases to the version on iTunes Connect.
  • Then try to test, if still not then submit app once then cancel it. then after try to test on your device.
  • Make sure when you test with sandbox user, you need to sign-out from your already logged in account from device settings, and login with sandbox ID.
  • some screenshots might be helpful.

这篇关于在iOS中进行应用购买测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆