A complete example of integrating the Teak SDK into a SwiftUI iOS app using CocoaPods. This project demonstrates SDK initialization, push notifications (including rich push with notification extensions), deep linking, reward handling, and player properties.
This is the companion example project for the Teak iOS Quickstart Guide.
| Target | Purpose |
|---|---|
| TeakCocoaPodsExample | Main SwiftUI app with Teak SDK initialization, user login, deep links, and reward handling |
| TeakNotificationService | Notification Service Extension for processing push payloads |
| TeakContentExtension | Notification Content Extension for rich, interactive push notifications |
If you don't have a Teak account yet, sign up and create a game project by following the Initial Setup guide. You'll also need to configure your iOS Push Credentials in the Teak dashboard.
-
Clone the repository:
git clone https://github.com/GoCarrot/TeakCocoaPodsExample.git cd TeakCocoaPodsExample -
Install dependencies:
pod install
-
Open the workspace (not the
.xcodeproj):open TeakSwiftCleanroomPods.xcworkspace
-
Replace the placeholder credentials in
TeakSwiftCleanroomPodsApp.swiftwith your own:Teak.initSwiftUI(forApplicationId: "<YOUR_APP_ID>", andApiKey: "<YOUR_API_KEY>")
-
Update the URL scheme in your target's Info tab. Teak requires a URL scheme of
teak<YOUR_APP_ID>(e.g.teak1234567890) for deep link handling. -
Build and run on a device or simulator.
In a SwiftUI app, initialize Teak in your App struct's init() and use @UIApplicationDelegateAdaptor to bridge UIKit lifecycle events:
import SwiftUI
import Teak
@main
struct TeakSwiftCleanroomPodsApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
init() {
Teak.initSwiftUI(forApplicationId: "<YOUR_APP_ID>", andApiKey: "<YOUR_API_KEY>")
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}Call Teak.login to identify the current player. Use your game's existing player ID — the same one your backend uses to store progress.
Teak.login("<YOUR_PLAYER_ID>", with: TeakUserConfiguration())
Teak.setStringProperty("favorite_slot", value: "demo")
Teak.setNumberProperty("bankroll", value: 12345)This example requests permissions at launch for simplicity. In a production app, request permissions at a contextually appropriate moment (e.g. after the player has had a chance to engage with the game):
Teak.requestNotificationPermissions { accepted, error in
print("Player accepted notifications: \(accepted)")
}Register routes to handle deep links sent via Teak notifications:
Teak.registerDeepLinkRoute("/slots/:slot_name", name: "Go to Slot",
description: "Take the player directly to a slot") { params in
print("Taking the player to \(params["slot_name"]!)")
}Observe TeakOnReward notifications to process rewards attached to push notifications:
NotificationCenter.default.addObserver(
forName: Notification.Name(TeakOnReward), object: nil, queue: nil) { notification in
let status = notification.userInfo!["status"] as! String
switch status {
case "grant_reward": print("Reward Granted!")
case "already_clicked": print("Already claimed!")
default: break
}
}Teak uses two notification extensions for rich push support. Both are thin subclasses that delegate to the SDK — the Teak framework handles the heavy lifting.
Processes incoming push payloads (e.g. decryption, media attachment downloads):
import TeakExtension
class NotificationService: TeakNotificationServiceCore {
override func serviceExtensionTimeWillExpire() {
super.serviceExtensionTimeWillExpire()
}
}Renders rich, interactive notification UI:
import TeakExtension
class NotificationViewController: TeakNotificationViewControllerCore {
override func viewDidLoad() {
super.viewDidLoad()
}
}Both extension targets use the Teak/Extension subspecs in the Podfile:
target 'TeakNotificationService' do
use_frameworks!
pod 'Teak/Extension'
end
target 'TeakContentExtension' do
use_frameworks!
pod 'Teak/Extension'
endFor the full walkthrough on creating these extensions, see Install the Teak SDK (CocoaPods).
When adapting this example for your own app, verify:
- Push Notifications capability is enabled (creates the
.entitlementsfile withaps-environment) - Background Modes — "Remote notifications" is checked in Info.plist
- URL Scheme —
teak<YOUR_APP_ID>is added under URL Types in your target's Info tab - Credentials — Your App ID and API Key from the Teak dashboard are set in your
App.init() - Player ID —
Teak.loginis called with your game's unique player identifier
Once the app is running and you've granted notification permissions, follow the Sending Your First Notification guide to verify everything is working end-to-end.
Licensed under the Apache License, Version 2.0. See LICENSE for details.