SKProductsrequest returns nothing in Swift

I've tried this issue for a couple of hours. I tried something like:

  • confirm Bundle ID and Product ID are absolutely correct
  • uninstall and reinstall the app on both simulators and real devices
  • I tried "productID" and "com.company.project.productID"
  • The IAP in the iTunes connection must also be configured correctly.

The only thing I'm not sure is that I am not filling out banking and tax stuff in my iTunes connect. Actually, I just filled out the bank information, but it takes 24 hours to update.

My codes are as follows

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    // Set IAPS
    if(SKPaymentQueue.canMakePayments()) {
        println("IAP is enabled, loading")
        var productID:NSSet = NSSet(objects: "ProductID")
        var request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>)
        request.delegate = self
        request.start()
    } else {
        println("please enable IAPS")
    }      
}

func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
    println("product request")
    var myProduct = response.products

    for product in myProduct {
        println("product added")
        println(product.productIdentifier)
        println(product.localizedTitle)
        println(product.localizedDescription)
        println(product.price)

        list.append(product as! SKProduct)
    }
}

      

This code is from example, it worked very well in my simulator. But when I replace ProductID with my own product ID (bundleID of course), the SKProductsrequest is not returned.

I have no idea why, hopefully someone can help me. thank!

+3


source to share


1 answer


I've had this problem all week - no matter what I tried using the code and tweaking the build and customization settings, I didn't get any products.

What finally fixed for me is changing the bundle id for my xcode app from company.appname

to com.company.appname

. In the meantime, you want to reference your in-app purchase IDs in format com.company.appname.thingforpurchase1

etc.

In an attempt to resolve this issue, I re-ran the project-wide auto provisioning and build customization process, and I added my developer account back to xcode. After that, the syntax worked for me. Note that when connecting itunes, my app's bundle id is still listed once company.appname

, but for some reason in xcode it also needs it com.

.

There is one more thing I had to do differently with Swift 2.0 vs Swift 1.x - the compiler will no longer accept the product ID anymore NSSet

- instead the request seems to want the IDs to be specified as a Set<String>

- see this in the example below.



Please note that this solution was developed and works in swift versions 2.0 and xcode 7.

Example:

func requestProductInfo() {
    print("about to fetch product info")
    if SKPaymentQueue.canMakePayments() {
            let request = SKProductsRequest(productIdentifiers:
                Set(productIDs))

            let productIdentifiers: NSSet = NSSet(array: productIDs) // NSset might need to be mutable
            let productRequest : SKProductsRequest = SKProductsRequest(productIdentifiers: productIdentifiers as! Set<String>)

            //we set our class as its delegate (so we can handle the response)& trigger the request.
            productRequest.delegate = self
            productRequest.start()
            print("Fetching Products");
        }
        else {
            print("can't make purchases")
        }
    }

      

+5


source







All Articles