Skip to content

Instantly share code, notes, and snippets.

@iAmWillShepherd
Last active April 24, 2024 20:22
Show Gist options
  • Save iAmWillShepherd/5522fb3efc67983160e244818c6e6b38 to your computer and use it in GitHub Desktop.
Save iAmWillShepherd/5522fb3efc67983160e244818c6e6b38 to your computer and use it in GitHub Desktop.
Snippet showing OneSignal User Model SDK initialization in Swift for Apple devices.
import SwiftUI
import DotEnv
import OneSignalFramework
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: UIResponder, UIApplicationDelegate, OSInAppMessageLifecycleListener {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
let env = DotEnv(withFile: ".env")
env.load()
OneSignal.initialize(env.get("ONESIGNAL_APP_ID"), withLaunchOptions: launchOptions)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment