A table view based view controller to show in app purchase items and functionality quickly within app based on SwiftStoreKit library.
MIT License
let iAP_RemoveAd = "net.yourcompany.product"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
loadStore()
return true
}
func loadStore(){
StoreManager.shared.completeTransactionAtAppLaunch()
StoreManager.shared.shouldAddStorePaymentHandling(true)
StoreManager.shared.storeItems = [
Product(name: "Restore", productId: StoreManager.RestoreAll, price: "", purchased: false, image: "iap_restore"),
Product(name: "Remove Ads", productId: iAP_RemoveAd, price: "", purchased: false, image: "iap_remove_ads"),
]
StoreManager.shared.loadStoreProducts()
}
import UIKit
import MBProgressHUD
import SimpleStoreUI
extension UIViewController {
//MARK: - Top View Controller
static func topViewController()-> UIViewController{
var topViewController:UIViewController = UIApplication.shared.keyWindow!.rootViewController!
while ((topViewController.presentedViewController) != nil) {
topViewController = topViewController.presentedViewController!;
}
return topViewController
}
}
class ViewController: UIViewController {
@IBAction func showStore(_ sender: Any) {
//Main code to add the Store UI within app
let bundle = Bundle(for: StoreViewController.self)
let storeVC = StoreViewController(nibName: "StoreViewController", bundle: bundle)
StoreManager.shared.storeManagerDelegate = self
storeVC.title = "Store"
self.navigationController?.pushViewController(storeVC, animated: true)
}
}
extension ViewController : StoreManagerDelegate {
//MARK:- HudDelegate
public func showHud() {
print("Show HUD")
MBProgressHUD.showAdded(to: UIViewController.topViewController().view, animated: true)
}
public func hideHud() {
MBProgressHUD.hide(for: UIViewController.topViewController().view, animated: true)
}
public func purchaseSuccess(productId: String) {
if productId == iAP_RemoveAd {
// TODO: DO SOMETHING
print("Remove Ads Purchase Success. Do Something!")
}
}
}
StoreManager.shared.isProductPurchased(Constants.kIAPRemoveAds)
Either
or
pod 'SimpleStoreUI'
or
pod 'SimpleStoreUI', :git => 'https://github.com/mahmudahsan/SimpleStoreUI'
Feel free to open an issue, or find me @mahmudahsan on Twitter.