I'm implementing In App purchases which work quite well. I'm implementing both Auto-Renewable and Non-renewable subscriptions. I can determine when either subscription is active and expired as well. I can update the user Profile UI according the status of subscription but can only do it when i check one at a time.
If i call both functions when the view is about to appear. The UI gets messed up and doesn't display the correct status. I have debugged and seen that if first one checks one subscription, updates its status, when i move out of the view and come back it checks the other goes back to the default status which is standard account because Auto-renewable is expired. Is there a way i run both functions at the same time and also use them to update my UI at the same time. Below is my code.
var isUserActive: Bool?
var user: User {
return AppDelegate.shared.user
}
func setUserAccountType() {
if self.isUserActive == nil {
self.userAccountType.text = ""
self.userGoGold.isHidden = true
} else {
if self.isUserActive! {
self.userAccountType.text = "Gold Account"
} else {
self.userAccountType.text = "Standard Account"
self.userGoGold.isHidden = false
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
self.setUserAccountType()
IAPManager.shared.getProducts()
}
override func viewWillAppear(_ pAnimated: Bool) {
super.viewWillAppear(pAnimated)
self.checkForAutoRenewableSubscription()
self.checkForNonRenewableSubscription()
}
func setUpUserAccountStatus(_ pIsActive: Bool) {
DispatchQueue.main.async {
self.isUserActive = pIsActive
self.setUserAccountType()
self.reloadRowForIdentifier(.billing)
self.activityIndicator.hidesWhenStopped = true
self.activityIndicator.stopAnimating()
}
}
func checkForAutoRenewableSubscription() {
self.activityIndicator.startAnimating()
self.user.checkIfSubscriptionIsActive { (pIsActive) in
self.setUpUserAccountStatus(pIsActive)
}
}
func checkForNonRenewableSubscription() {
self.activityIndicator.startAnimating()
self.user.checkifNonRenewableSubscriptionIsActive { (pSubscribed) in
self.setUpUserAccountStatus(pSubscribed)
}
}
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)