Skip to content

Instantly share code, notes, and snippets.

View ren6's full-sized avatar

Renat Kurbanov ren6

View GitHub Profile
func expirationDateFor(_ identifier : String) -> Date?{
return UserDefaults.standard.object(forKey: identifier) as? Date
}
let subscriptionDate = IAPManager.shared.expirationDateFor("YOUR_PRODUCT_ID") ?? Date()
let isActive = subscriptionDate > Date()
@ren6
ren6 / IAPManager.swift
Created June 18, 2019 10:36
This is a class that handles process of purchasing, validating subscriptions, refreshing receipt, restoring transactions.
//
// IAPManager.swift
// http://apphud.com
//
// Created by Apphud on 04/01/2019.
// Copyright © 2019 Apphud. All rights reserved.
//
import UIKit
import StoreKit
@ren6
ren6 / eligibility.swift
Last active December 16, 2020 23:32
Determining eligibility for introductory offer
func isEligibleForIntroductory(callback: @escaping (Bool) -> Void){
guard let receiptUrl = Bundle.main.appStoreReceiptURL else {
callback(true)
return
}
#if DEBUG
let urlString = "https://sandbox.itunes.apple.com/verifyReceipt"
#else
@ren6
ren6 / app_store_receipt_example.json
Created October 15, 2019 12:57
Example of App Store receipt with 2 auto-renewable transactions (trial and renewal)
{
"status": 0,
"environment": "Sandbox",
"receipt": {
"receipt_type": "ProductionSandbox",
"adam_id": 0,
"app_item_id": 0,
"bundle_id": "com.apphud.subscriptionstest",
"application_version": "1",
"download_id": 0,
{
"latest_receipt": "long_base64_receipt_here...",
"latest_receipt_info": {
"original_purchase_date_pst": "2020-04-01 01:12:42 America/Los_Angeles",
"quantity": "1",
"subscription_group_identifier": "20537620",
"unique_vendor_identifier": "A779C77C-571E-477D-B184-474DBD2F3F5C",
"original_purchase_date_ms": "1585728762000",
"expires_date_formatted": "2020-04-01 08:17:41 Etc/GMT",
"is_in_intro_offer_period": "true",