mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-09 22:35:56 +05:45
* import Purchases -> import RevenueCat * updated Pod name to Purchases * updated more Pod names
66 lines
2.3 KiB
Swift
66 lines
2.3 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// SwiftExample
|
|
//
|
|
// Created by Ryan Kotzebue on 1/9/19.
|
|
// Copyright © 2019 RevenueCat. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import UserNotifications
|
|
import RevenueCat
|
|
|
|
@UIApplicationMain
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
var window: UIWindow?
|
|
|
|
func application(_ application: UIApplication,
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
|
|
Purchases.debugLogsEnabled = true
|
|
Purchases.configure(withAPIKey: <your_public_sdk_key_here>)
|
|
|
|
// 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
|
|
requestPushNotificationsPermissions()
|
|
|
|
Purchases.shared.checkTrialOrIntroductoryPriceEligibility(["com.revenuecat.monthly_4.99.1_week_intro"]) { introEligibilityDict in
|
|
print(introEligibilityDict)
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
Purchases.shared.setPushToken(deviceToken)
|
|
}
|
|
|
|
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
print("Failed to register: \(error)")
|
|
}
|
|
|
|
private func requestPushNotificationsPermissions() {
|
|
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()
|
|
}
|
|
}
|
|
}
|
|
}
|