Ok, thanks. Here is my code designed to check if purchased/purchase and then equip the icon, and refresh. However, the part with the if runs before it can be purchased, if it is already purchased then it works fine.
func setIcon(name: String) {
IconChange.setIconPurchased = false
print(name)
let app = UIApplication.shared
if #available(iOS 10.3, *) {
if app.supportsAlternateIcons {
checkForUnlocked(name: name)
if IconChange.setIconPurchased == true {
app.setAlternateIconName(name, completionHandler: { (error) in
if error != nil {
print("error = \(String(describing: error?.localizedDescription))")
// Create new Alert
let dialogMessage = UIAlertController(title: "Failed to change icon", message: "There was an error changing the icon: \(error!)", preferredStyle: .alert)
// Create OK button with action handler
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) - Void in
print("\"Failed to change icon\" alert was dismised")
})
//Add OK button to a dialog message
dialogMessage.addAction(ok)
// Present Alert
self.present(dialogMessage, animated: true, completion: nil)
}else {
print("Changed Icon Sucessfully.")
self.iconSelected = name
UserDefaults.standard.setValue(name, forKey: "iconSelected")
IconChange.pushBack = true
self.navigationController?.popViewController(animated: true)
}
})
}
}
}
}