Skip to content

Instantly share code, notes, and snippets.

@rkotzy
rkotzy / 4sq_categories-emoji.swift
Last active January 30, 2021 06:20
Trying to map all the Foursquare categories (https://developer.foursquare.com/categorytree) to emojis ✌️
let categories = [
"55a5a1ebe4b013909087cbb6" : "🍝", // AbruzzoRestaurant
"5294c7523cf9994f4e043a62" : "🍓", // AcaiHouse
"4bf58dd8d48988d102951735" : "💄", // AccessoriesStore
"52960eda3cf9994f4e043ac9" : "🍴", // AcehneseRestaurant
"52e81612bcbc57f1066b7a3b" : "🏥", // Acupuncturist
"56aa371ce4b08b9a8d573570" : "🏫", // Adult Education Centers
"5267e446e4b0ec79466e48c4" : "👗", // AdultBoutique
"52e81612bcbc57f1066b7a3d" : "🏢", // AdvertisingAgency
"503288ae91d4c4b30a586d67" : "🍴", // AfghanRestaurant
@rkotzy
rkotzy / notifications.swift
Created August 2, 2017 16:51
Fire Local Notifications in Swift
func fireNotification(title: String?, body: String?, id: String) {
let content = UNMutableNotificationContent()
if let title = title {
content.title = title
}
if let body = body {
content.body = body != "" ? body : "arrival"
}
content.sound = UNNotificationSound.default()
@rkotzy
rkotzy / BuildConfig.swift
Created March 1, 2019 18:55
Determine what environment your iOS app is running in
import Foundation
enum AppConfiguration : String {
case debug = "debug"
case testFlight = "testFlight"
case appStore = "appStore"
}
struct Config {
// This is private because the use of 'appConfiguration' is preferred.
@available(iOS 12.2, *)
func showPromoUpsell() {
Purchases.shared.entitlements { (entitlements, error) in
// 1: - Get the discount for the product we want to offer
//
guard let product = entitlements?["pro_cat"]?.offerings["monthly_cats"]?.activeProduct else {
print("Error finding monthly_cat product")
return
func configureCatContentFor(purchaserInfo: PurchaserInfo?) {
if let purchaserInfo = purchaserInfo {
if purchaserInfo.activeEntitlements.contains("pro_cat") {
// ...
// ...
// ...
} else {
func shouldShowSubscriptionOffer(_ purchaserInfo: PurchaserInfo) -> Bool {
// Check that the user has a 'pro_cat' entitlement that expired >= 7 days ago
// and check that we haven't previously shown this offer to the user
if (purchaserInfo.expirationDate(forEntitlement: "pro_cat") ?? Date()).addingTimeInterval(7*86400) <= Date() &&
!UserDefaults.standard.bool(forKey: "has_seen_promo_cat_discount")
{
return true
}
@available(iOS 12.2, *)
func showPromoUpsell() {
Purchases.shared.entitlements { (entitlements, error) in
// 1: - Get the discount for the product we want to offer
//
guard let product = entitlements?["pro_cat"]?.offerings["monthly_cats"]?.activeProduct else {
print("Error finding monthly_cat product")
return
// 2: - Fetch the payment discount
//
Purchases.shared.paymentDiscount(for: productDiscount, product: product, completion: { (paymentDiscount, err) in
guard let discount = paymentDiscount else {
print("Payment discount doesn't exist. Check error.")
return
}
// ... continued
// 3: - Show the user the offer to purchase and save a flag
// in local storage so we don't show again
self.presentPromoAlert(productDiscount, shouldPurchase: {
Purchases.shared.makePurchase(product, discount: discount, { (transaction, info, error, cancelled) in
self.configureCatContentFor(purchaserInfo: info)
})
})
// ... continued
import Purchases
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {