in Education by
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)

1 Answer

0 votes
by
You need to use DispatchGroup and inside it's notify part do what you need let dispatchGroup = DispatchGroup() var inpIsActive = false var inpSubscribed = false func checkForAutoRenewableSubscription() { dispatchGroup.enter() self.activityIndicator.startAnimating() self.user.checkIfSubscriptionIsActive { (pIsActive) in self.inpIsActive = pIsActive self.dispatchGroup.leave() } } func checkForNonRenewableSubscription() { dispatchGroup.enter() self.activityIndicator.startAnimating() self.user.checkifNonRenewableSubscriptionIsActive { (pSubscribed) in self.inpSubscribed = pSubscribed self.dispatchGroup.leave() } } And inside viewDidLoad checkForAutoRenewableSubscription() checkForNonRenewableSubscription() dispatchGroup.notify(queue: .main) { self.setUpUserAccountStatus() }

Related questions

0 votes
    I'm implementing In App purchases which work quite well. I'm implementing both Auto-Renewable and Non- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I'm trying to include actual date and time to the certain message, however I'm unable to do it, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have a store to get a list of something in system. To get information by business requirement, this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
0 votes
    Context: I have been writing automated test scripts with Appium for quite a while and everything works well ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I had some Python 2 code as follows (pardon the indentation): def getZacksRating(symbol): c = httplib.HTTPSConnection("www. ... data.split(' ')[1] result = ratingPart.partition("...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Can a neural network learn & recall at the same time? (a) yes (b) no I got this question in class ... and Synaptic Dynamics of Neural Networks Please answer the above question....
asked Sep 5, 2022 in Education by JackTerrance
0 votes
    Can system be both interpolative & accretive at same time? (a) yes (b) no I have been asked this ... Neural Networks of Neural Networks Please answer the above question....
asked Sep 3, 2022 in Education by JackTerrance
0 votes
    "At the same time this visibility does not mean popularity." Explain Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    To configure the admin settings of my app I made a Admin controller and a AdminConfig model. The Admin ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    To configure the admin settings of my app I made a Admin controller and a AdminConfig model. The Admin ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I am trying to set text and value for both td tag and input tag at the same time. But after ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I am trying to set text and value for both td tag and input tag at the same time. But after ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
...