美文网首页
oc 调用swiftUI 2024-05-17

oc 调用swiftUI 2024-05-17

作者: iOS打怪升级 | 来源:发表于2024-05-16 14:19 被阅读0次
  1. 需要把swiftUI 的类通过swift 封装,然后oc 调用swift 的方法,没法直接oc 调用swiftUI 的方法
//
//  FefundAppleManager.swift
//  xingxueapp
//
//  Created by litianqi on 2024/5/13.
//  Copyright © 2024 edu24ol. All rights reserved.
//

import Foundation
import StoreKit
import SwiftUI

 
@objc
class RefundAppleManager :NSObject {
    
    @available(iOS 15.0, *)
    
//    @objc
//    class func beginFefundRequest(){
//        let view = RefundSwiftUIView()
//        let
//    }
    
    @objc
    class  func  hq_refundRequest (transactionID: UInt64, viewController: UIViewController) {
        let view = RefundSwiftUIView(transactionID)
        let controller = UIHostingController(rootView: view)
        viewController.navigationController?.pushViewController(controller, animated: true)
    
    }
    
}

  • siwftUI 类
//
//  FefundSwiftUIView.swift
//  xingxueapp
//
//  Created by litianqi on 2024/5/13.
//  Copyright © 2024 edu24ol. All rights reserved.
//

import SwiftUI
import StoreKit

@available(iOS 15.0, *)
struct RefundSwiftUIView: View {
    @State private var isRefundSheetPresented = false
    let transactionID: StoreKit.Transaction.ID // 替换为你的交易ID
    var windowScene: UIWindowScene?
    init(_ transactionID: StoreKit.Transaction.ID) {
        self.transactionID = transactionID
    }
    
    func beginRefund(){
       
//        SKPaymentQueue.default().
    }
    
    
    var body: some View {
        Button("Request Refund") {
            isRefundSheetPresented = true
//             windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
//            if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
//               
////                SKPaymentQueue.default().beginRefundRequest(in: windowScene)
//            }
          
        }
//        .beginRefundRequest(in: windowScene)
        .refundRequestSheet(for: transactionID, isPresented: $isRefundSheetPresented) { result in
            switch result {
            case .success(let status):
                print("Refund request status: \(status)")
            case .failure(let error):
                print("Failed to request refund: \(error)")
            }
        }
    }
}

@available(iOS 15.0, *)
struct FefundSwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        RefundSwiftUIView(0)
    }
}

相关文章

网友评论

      本文标题:oc 调用swiftUI 2024-05-17

      本文链接:https://www.haomeiwen.com/subject/vwobfjtx.html