I have been trying to get StoreKit to work over the last 2 days. I found many possible faults and remedies via stack overflow. I haven't seen this particular problem mentioned anywhere.
The first code snippet shows what works in my project. It uses a hardcoded product ID string and returns a SKProduct via the appropriate delegate function. It works on both a device and the simulator (iOS 8.4).
private var request : SKProductsRequest?
func fetchProducts()
{
self.request = SKProductsRequest(productIdentifiers: Set(["TestProductA","Test Product A"]))
self.request?.delegate = self
self.request?.start()
}
But if I use the same product ID loaded from a plist, then it doesn't work anymore. I immediately get the typically vague error "cannot connect to store". Why this is not working escapes me for the moment.
func fetchProducts()
{
if let productList = NSBundle.mainBundle().URLForResource("Products", withExtension: "plist"),
let productIdentifiers = NSArray(contentsOfURL: productList) as? [String]
{
self.request = SKProductsRequest(productIdentifiers: Set(arrayLiteral: productIdentifiers))
self.request?.delegate = self
self.request?.start()
}
}
Found the solution. I had to change how the set is created.
self.request = SKProductsRequest(productIdentifiers: Set<String>(productIdentifiers))