0

How can I present a View Controller from the class above after I buy an in-app purchase product?


import Foundation
import StoreKit

class IAPService: NSObject {

    private override init() {}
    static let shared = IAPService()

    var products = [SKProduct]()
    let paymentQueue = SKPaymentQueue.default()

 //......some more IAP code here...
func presentVC(){ What to write here??? }
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Lucian
  • 127
  • 1
  • 7

1 Answers1

0

Since a subclass of NSObject has no navigation capability , you need to either

1- Use a delegate by adding this var

weak var myController:VCName?

and init it whenever you want ( before the usage so the navigation will function ) then use

myController?.present(anotherVC,animated:true)

2- Use Application's rootVC ( but note it may be presenting another vc at that time so it may/not function as this depends on your navigation structure )

UIApplication.shared.keyWindow?.rootViewController?.present..........
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87