gpt4 book ai didi

ios - 从 NSObject 类中呈现一个 View Controller

转载 作者:行者123 更新时间:2023-11-30 11:03:37 26 4
gpt4 key购买 nike

购买应用内购买产品后,如何呈现上述类中的 View Controller ?


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??? }

最佳答案

由于 NSObject 的子类没有导航功能,因此您需要:

1- 通过添加此变量来使用委托(delegate)

weak var myController:VCName?

并在需要时初始化它(在使用之前,以便导航正常运行),然后使用

myController?.present(anotherVC,animated:true)

2-使用应用程序的rootVC(但请注意,当时它可能会呈现另一个VC,因此它可能/不起作用,因为这取决于您的导航结构)

UIApplication.shared.keyWindow?.rootViewController?.present..........

关于ios - 从 NSObject 类中呈现一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52997525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com