小编Luk*_*kas的帖子

Swift:促销产品(使用 RevenueCat)- 缓存 defermentBlock

目前,我正在尝试在 RevenueCat 的帮助下将促销产品包含在我的应用程序中。不幸的是它不起作用。(我使用的是 SwiftUI 1.0,所以仍然使用 AppDelegate。)

到目前为止我所做的:

我已经在 AppDelegate 中实现了以下功能,如此处所述(https://docs.revenuecat.com/discuss/5cff570754c3420045b379f3):

  func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock){
    let defermentBlock = makeDeferredPurchase
    
  }
Run Code Online (Sandbox Code Playgroud)

问题:

我认为问题是我在错误的地方运行 defermentBlock。正如这里所说(https://sdk.revenuecat.com/ios/Protocols/RCPurchasesDelegate.html#/c:objc(pl)RCPurchasesDelegate(im)purchases:shouldPurchasePromoProduct:defermentBlock:),应该在应用程序启动时调用它处于正确的状态。

目前我直接在函数中调用 defermentBlock,如下所示:

func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock){
    let defermentBlock = makeDeferredPurchase
    
    // Should buy the product 
    defermentBlock { (transaction, info, error, cancelled) in
        if let purchaserInfo = info {
            Purchases.shared.purchaseProduct(product) { (transaction, purchaserInfo, error, userCancelled) in //this function works for products …
Run Code Online (Sandbox Code Playgroud)

caching in-app-purchase swift revenuecat swiftui

5
推荐指数
1
解决办法
935
查看次数

SwiftUI:点击切换并且变量状态发生变化时调用函数

我知道已经有一个关于该主题的线程(How can I trigger an action when a swiftUI toggle() is Switched?),但我尝试了每个答案,但没有任何效果。

首先是我的代码:

struct ContentView: View {
    
    @State private var isOn = false
    
    
    var body: some View {
        
        NavigationView{
            VStack{
                ZStack {
                    Form{
                        // HERE THE IMPORTANT PART

                        Toggle(isOn: %isOn) {
                            Text(isOn ? "On" : "Off")
                            
                            /*if(isOn){
                                Text("\(sendState(state: isOn))")
                            }else{
                                Text("\(sendState(state: isOn))")
                            }*/
                              //--> that is a workaround but doesn't work for me because the function send something to the server and that should only happen when the …
Run Code Online (Sandbox Code Playgroud)

binding state function toggle swiftui

2
推荐指数
1
解决办法
4210
查看次数

Swift 委托从未被调用

我知道这个问题已经在论坛中存在,但我不知道为什么我的代表不起作用。顺便说一下,我是第一次和他们一起工作。

这是代码

视图控制器:

class ViewController: UIViewController, ContainerViewControllerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        let controller = ContainerViewController()
        controller.containerDelegate = self

    }

    func didScrollChangeAppearanceBarButtonItem(change: Bool) {
        if(change == true){
            print("true")
        }else{
            print("false")
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

容器视图:

protocol ContainerViewControllerDelegate {
     func didScrollChangeAppearanceBarButtonItem(change: Bool)
}

class ContainerViewController: UIViewController, UIScrollViewDelegate{

    var containerDelegate: ContainerViewControllerDelegate?

    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

        if(velocity.y>0) {
            containerDelegate?.didScrollChangeAppearanceBarButtonItem(change: false)
            print("1")

        } else {
            containerDelegate?.didScrollChangeAppearanceBarButtonItem(change: true)
            print("2")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想做的事情:当我滚动时,我想向我的 ViewController 发送一个布尔值。当 bool == true 时我想做某事,当 bool …

delegates protocols ios uicontainerview swift

1
推荐指数
1
解决办法
637
查看次数