目前,我正在尝试在 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) 我知道已经有一个关于该主题的线程(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) 我知道这个问题已经在论坛中存在,但我不知道为什么我的代表不起作用。顺便说一下,我是第一次和他们一起工作。
这是代码
视图控制器:
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 …