SwiftUI・SubscriptionStoreView
Discussion
StoryboardでのSwiftUIの実装
まずStoryboardのViewの種類の中からHostingViewControllerを探します。
そして、NavigationViewControllerのRootViewに開始画面をセット。
そして、Push segueをNvigationViewControllerから、HostingViewControllerの次のViewControllerへ伸ばします。
次に、開始画面のViewControllerからHostingViewControllerPush segueを伸ばし両方のSegueにIDをふりわけます。この作業は、View間のSegueのLineをクリックしツールバーで名づけます。
次に開始画面ViewControllerにつないでいるSegueのLineの中央の丸部分からアシスタントエディターの開始画面ViewCotroller.swiftにドラッグアンドドロップします。すると以下の通りの文字列が現れます。
override func viewDidLoad() {
self.view.backgroundColor = .black
let button = UIButton()
button.frame = self.view.bounds
button.textColor = .brown
button.addTarget(self, action: #selector(button(button:)), for: .touchUpInside)
}
@IBSegueAction func segueOn(_ coder: NSCorder) -> UIViewController {
return UIHostingController(corder: coder, rootView: SwiftUIのクラスネーム)
}
@objc func button(button: UIButton) {
self.view.performSegue(withIdentifire: "segueのID(任意)", sender: self)
}
この後SwiftUIのclassName.swiftを作成します。
import SwiftUI
import StoreKit
struct className: View {
@State var isPresented: Bool = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Subscription(opened: $isPresented), isActive: $isPresented) {}
Button(action: {
isPresented = true
}) {
Text("KiraKira Music EQ").foregroundColor(.brown).font(.custom("IowanOldStyle-BoldItalic", size: 35)
}
}
}
}
}
struct Subscription: View {
@Binding var opened: Bool
var body: some View {
VStack {
SubscriptionStoreView(productIDs: ["com.Bundle.Id1", "com.Bundle.課金のID2", "com.Bundle>ID3"])
.inOnAppPurchaseStart{ Product in
switch SKPaymentTransactionState(rawValue: 0) {
.puchased, restored:
print("Purchased, restored")
UIApplication.shared.keyWindow?.rootViewController.performSegue(withIdentifire: "NavigtionControllerからのSegue ID", sender: nil)
break
.deffered, failed:
let product = SKProduct()
let payment = SKPayment(product: product)
SKPaymentQueue.default().add(payment)
break
.purchasing:
print("purchasing")
default:
break
}
}
.inOnAppPurchaseCompletion { Product arg in
// 課金完了後の処理。上記と同様も可
}
}
}
この課金Sandboxが必要である。
そこで、ファイルをテンプレートから作成で、.StoreKitというファイル形式を、メニューの一番下方から選ぶ。
この先どうする?
0 likes