I've implemented In-App-Purchase in my ios app. Here I've used RequestCompletionHandler
at SKProductsRequestDelegate
method as shown below. Some times app getting crash because nil
value. What is wrong in my code?
completionHandler
is declared as: fileprivate var completionHandler: RequestCompletionHandler!
func productsRequest(_ request: SKProductsRequest!, didReceive response: SKProductsResponse!) {
print("Successfully loaded list of products..")
productsRequest = nil
if response.products.count > 0 {
if let skProducts = response.products as? [SKProduct] {
for product in skProducts {
print("found product: \(product.productIdentifier), \(product.localizedTitle), \(product.price.floatValue)")
}
completionHandler(true, skProducts as NSArray) //unexpectedly found nil while unwrapping an optional value exception getting in this line
completionHandler = nil
}
}
}
See the screenshot below for better understanding: