Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Repository files navigation

MRInAppPurchaseView

SPM readyPlatformSwiftXcodeLicenseTwitter

Simple tableView for display and interact with in-app purchases

Requirements

  • iOS 13.0+
  • Xcode 13.0+
  • Swift 5.5+

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but MRInAppPurchaseView does support its use on supported platforms.

Once you have your Swift package set up, adding MRInAppPurchaseView as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies:[.package(url:"https://github.com/furiosFast/MRInAppPurchaseView.git", from:"1.0.0")]

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate MRInAppPurchaseView into your project manually.

Usage

Example

import MRInAppPurchaseView
import SwifterSwift
import UIKit
class IAPViewController:MRInAppPurchaseView,MRInAppPurchaseViewDelegate{varIAPDataList:[InAppPurchaseData]=[]overridefunc viewDidLoad(){
super.viewDidLoad()
inAppPurchaseView.delegate =self
inAppPurchaseView.setCellTitleFont(UIFont.systemFont(ofSize:20))}overridefunc viewWillAppear(_ animated:Bool){
super.viewWillAppear(animated)setupInAppPurchaseData()DispatchQueue.global().async{ifIAPManager.shared.products.count <IAPManager.shared.productIDS.count {IAPManager.shared.getProductInfo{self.setupInAppPurchaseData()DispatchQueue.main.async{self.inAppPurchaseView.reloadData()}}}}}
// MARK: - MRInAppPurchaseViewDelegate
func inAppPurchaseButtonTapped(inAppPurchase:InAppPurchaseData){letmanager=IAPManager.shared
if inAppPurchase.id == inAppId_proKit {proKit(manager)}else{restorePurchases(manager)}}
// MARK: - Private functions
privatefunc setupInAppPurchaseData(){IAPDataList.removeAll()
inAppPurchaseView.setInAppPurchases([])letmanager=IAPManager.shared //your in-app data manager
// pro kit
if !PurchasedInApp.proKit.isPurchased {letdata=InAppPurchaseData(inAppId_proKit, manager.productIcons[inAppId_proKit]!,loc("settings_PROKIT"),loc("settings_PROKITWIKI"),loc("inapp_BUY").uppercased())
data.wikiTextAlignment =.left
IAPDataList.append(data)}
// restore
letdata=InAppPurchaseData("restore", #imageLiteral(resourceName:"restore in-app"),loc("settings_RESTOREINAPP"),nil,loc("inapp_RESTORE").uppercased())
data.iconBorderColor =.clear
IAPDataList.append(data)
inAppPurchaseView.setInAppPurchases(IAPDataList)}
// in-app products actions
privatefunc proKit(_ manager:IAPManager){
if manager.products.count !=0{manager.purchaseProduct(productId: inAppId_proKit, completed:{ message in
if message.isEmpty {self.showAlert(title:"Success", message:"PRO Kit purchased", buttonTitles:["OK"])self.setupInAppPurchaseData()self.inAppPurchaseView.reloadData()}else{if message !=loc("inapp_UNKNOWERROR"){self.showAlert(title:"Warning"), message: message,buttonTitles:["OK"])}}self.inAppPurchaseView.setNomalStateToPurchaseButtonsFromProgress()})}else{
inAppPurchaseView.setNomalStateToPurchaseButtonsFromProgress()}}
private func restorePurchases(_ manager:IAPManager){if manager.products.count !=0{
manager.restorePurchases(completed:{[self] restoreMessage, purchase inif restoreMessage.isEmpty {
purchase.restoredPurchases.forEach{ purchase inswitch purchase.productId {case inAppId_proKit:do{
//do somethings...
default:break}}self.setupInAppPurchaseData()self.inAppPurchaseView.reloadData()self.showAlert(title:"Success", message:loc("inapp_RESTORESUCCESS"), buttonTitles:["OK"])} else {self.showAlert(title:"Warning", message: restoreMessage, buttonTitles:["OK"])}self.inAppPurchaseView.setNomalStateToPurchaseButtonsFromProgress()})}else{
inAppPurchaseView.setNomalStateToPurchaseButtonsFromProgress()}}

And now open show 'inAppPurchaseView' from your ViewController

classViewController:UIViewController{
//MARK: - IBActions
@IBActionfunc showIAPViewController(_ sender:Any){letiapVC=IAPViewController()
iapVC.navigationItem.title =loc("settings_INAPPHEADERTEXT")letnavC=UINavigationController(rootViewController: iapVC)present(navC, animated:true)}}

Requirements

MRInAppPurchaseView has different dependencies and therefore needs the following libraries (also available via SPM):

It isn't necessary to add the dependencies of MRInAppPurchaseView, becose with SPM all is do automatically!

License

MRInAppPurchaseView is released under the MIT license. See LICENSE for more information.

About

Simple tableView for display and interact with in-app purchases

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages