A modern SwiftUI example app demonstrating the OneSignal iOS SDK features using MVVM architecture.
This example app demonstrates all major OneSignal SDK capabilities:
- User Management: Login/logout with external user ID
- Aliases: Add and remove user aliases
- Push Subscriptions: Enable/disable push notifications, view push ID
- Email & SMS: Add and remove email and SMS subscriptions
- Tags: Manage user tags for segmentation
- Outcomes: Track outcome events with optional values
- In-App Messaging: Pause/resume IAM, manage triggers
- Location: Toggle location sharing, request permissions
- Test Notifications: Grid of notification types for testing
The app follows the MVVM (Model-View-ViewModel) pattern:
OneSignalSwiftUIExample/
├── App/
│ └── OneSignalSwiftUIExampleApp.swift # App entry point, SDK init
├── Views/
│ ├── ContentView.swift # Main view
│ ├── Sections/ # Feature sections
│ │ ├── AppInfoSection.swift
│ │ ├── UserSection.swift
│ │ ├── SubscriptionSection.swift
│ │ ├── TagsSection.swift
│ │ ├── MessagingSection.swift
│ │ ├── LocationSection.swift
│ │ └── NotificationSection.swift
│ └── Components/ # Reusable UI components
│ ├── KeyValueRow.swift
│ ├── AddItemSheet.swift
│ ├── NotificationGrid.swift
│ └── ToastView.swift
├── ViewModels/
│ └── OneSignalViewModel.swift # Main ViewModel
├── Models/
│ └── AppModels.swift # Data models
├── Services/
│ └── OneSignalService.swift # SDK wrapper
└── Assets.xcassets/ # App assets
- Open Xcode and create a new project
- Select iOS → App
- Configure the project:
- Product Name:
OneSignalSwiftUIExample - Team: Your development team
- Organization Identifier:
com.onesignal - Interface: SwiftUI
- Language: Swift
- Storage: None
- Product Name:
- Save the project in
iOS_SDK/OneSignalSwiftUIExample/
- Delete the auto-generated
ContentView.swiftandOneSignalSwiftUIExampleApp.swift - Drag all the folders from
OneSignalSwiftUIExample/into your Xcode project:App/Views/ViewModels/Models/Services/Assets.xcassets/
- Make sure "Copy items if needed" is unchecked and "Create groups" is selected
- In Xcode, go to File → Add Package Dependencies...
- Enter the OneSignal SDK repository URL:
https://github.com/OneSignal/OneSignal-iOS-SDK - Select version 5.0.0 or later
- Add the following packages to your main target:
OneSignalFrameworkOneSignalInAppMessagesOneSignalLocation
If you're developing the SDK locally:
- Drag the parent
OneSignal-iOS-SDKfolder into your project - Or add local package dependency pointing to the repo root
- Select your project in the navigator
- Select your app target
- Go to Signing & Capabilities
- Add the following capabilities:
- Push Notifications
- Background Modes → Check "Remote notifications"
The included Info.plist already has the required keys:
NSLocationWhenInUseUsageDescriptionNSLocationAlwaysAndWhenInUseUsageDescriptionUIBackgroundModeswithremote-notification
The default OneSignal App ID is configured in OneSignalService.swift. To use your own:
- Open
Services/OneSignalService.swift - Change the
defaultAppIdvalue to your OneSignal App ID
- Select a simulator or device
- Build and run (⌘R)
- Grant notification permissions when prompted
- Explore the various OneSignal features
- iOS 15.0+
- Xcode 15.0+
- Swift 5.9+
- OneSignal iOS SDK 5.0+
Modified MIT License - See LICENSE file for details.