2019-01-31 12:46:25 -08:00
|
|
|
//
|
|
|
|
|
// AppDelegate.swift
|
|
|
|
|
// SwiftExample
|
|
|
|
|
//
|
|
|
|
|
// Created by Ryan Kotzebue on 1/9/19.
|
|
|
|
|
// Copyright © 2019 RevenueCat. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2020-03-16 18:17:32 -03:00
|
|
|
import UserNotifications
|
2021-09-03 14:17:37 -03:00
|
|
|
import RevenueCat
|
2019-01-31 12:46:25 -08:00
|
|
|
|
|
|
|
|
@UIApplicationMain
|
|
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
|
|
|
|
|
|
var window: UIWindow?
|
|
|
|
|
|
2020-03-16 18:17:32 -03:00
|
|
|
func application(_ application: UIApplication,
|
|
|
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
2019-01-31 12:46:25 -08:00
|
|
|
|
|
|
|
|
Purchases.debugLogsEnabled = true
|
2019-11-13 11:08:54 -08:00
|
|
|
Purchases.configure(withAPIKey: <your_public_sdk_key_here>)
|
2020-03-16 18:17:32 -03:00
|
|
|
|
|
|
|
|
// set attributes to store additional, structured information for a user in RevenueCat.
|
|
|
|
|
// More info: https://docs.revenuecat.com/docs/user-attributes
|
|
|
|
|
Purchases.shared.setAttributes(["favorite_cat" : "garfield"])
|
|
|
|
|
|
|
|
|
|
// we're requesting push notifications on app start only to showcase how to set the push token in RevenueCat
|
2020-03-17 16:53:39 -03:00
|
|
|
requestPushNotificationsPermissions()
|
2020-08-27 11:15:34 -03:00
|
|
|
|
|
|
|
|
Purchases.shared.checkTrialOrIntroductoryPriceEligibility(["com.revenuecat.monthly_4.99.1_week_intro"]) { introEligibilityDict in
|
|
|
|
|
print(introEligibilityDict)
|
|
|
|
|
}
|
2020-03-16 18:17:32 -03:00
|
|
|
|
2019-01-31 12:46:25 -08:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-16 18:17:32 -03:00
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
|
|
|
Purchases.shared.setPushToken(deviceToken)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
|
|
|
print("Failed to register: \(error)")
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 16:53:39 -03:00
|
|
|
private func requestPushNotificationsPermissions() {
|
2020-03-16 18:17:32 -03:00
|
|
|
let userNotificationCenter = UNUserNotificationCenter.current()
|
|
|
|
|
userNotificationCenter.requestAuthorization(options: [.alert, .sound, .badge]) { [weak self] granted, error in
|
|
|
|
|
print("Permission granted: \(granted)")
|
|
|
|
|
if granted {
|
|
|
|
|
self?.getNotificationSettings()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func getNotificationSettings() {
|
|
|
|
|
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
|
|
|
|
print("Notification settings: \(settings)")
|
|
|
|
|
guard settings.authorizationStatus == .authorized else { return }
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
UIApplication.shared.registerForRemoteNotifications()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|