Files
purchases-ios/Examples/LegacySwiftExample/SwiftExample/InitialViewController.swift
T

51 lines
1.9 KiB
Swift
Raw Normal View History

2019-01-31 12:46:25 -08:00
//
// InitialViewController.swift
// SwiftExample
//
// Created by Ryan Kotzebue on 1/9/19.
// Copyright © 2019 RevenueCat. All rights reserved.
//
import UIKit
import Purchases
class InitialViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Get the latest purchaserInfo to see if we have a pro cat user or not
Purchases.shared.purchaserInfo { (purchaserInfo, error) in
if let e = error {
print(e.localizedDescription)
}
2019-11-13 11:08:54 -08:00
// Route the view depending if we have a premium cat user or not
if purchaserInfo?.entitlements["pro_cat"]?.isActive == true {
2019-01-31 12:46:25 -08:00
2019-11-13 11:08:54 -08:00
// if we have a pro_cat subscriber, send them to the cat screen
2019-01-31 12:46:25 -08:00
let storyboard = UIStoryboard(name: "Main", bundle: nil)
2019-11-13 11:08:54 -08:00
let controller = storyboard.instantiateViewController(withIdentifier: "cats")
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
2019-01-31 12:46:25 -08:00
2019-11-13 11:08:54 -08:00
} else {
// if we don't have a pro subscriber, send them to the upsell screen
let controller = SwiftPaywall(
termsOfServiceUrlString: "https://www.revenuecat.com/terms",
privacyPolicyUrlString: "https://www.revenuecat.com/terms")
2019-01-31 12:46:25 -08:00
2019-11-13 11:08:54 -08:00
controller.titleLabel.text = "Upsell Screen"
controller.subtitleLabel.text = "New cats, unlimited cats, personal cat insights and more!"
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
2019-01-31 12:46:25 -08:00
}
}
}
}