Mobile Integration
Integrate Onairos into Swift, React Native, or Flutter applications.
Mobile Integration
Integrate Onairos into your mobile application with our native SDKs.
Create a Developer account at developer.onairos.uk and get your API key.
Installation
Swift (iOS)
Add via Swift Package Manager in Xcode: File → Add Package Dependencies
// Package URL
https://github.com/zd819/OnairosSwift
import OnairosSDK
Requirements: iOS 14.0+, Xcode 13.0+, Swift 5.5+
React Native
npm install @onairos/react-native
import { OnairosButton } from '@onairos/react-native';
Flutter
dart pub add onairos
import 'package:onairos/onairos.dart';
Quick Start
Swift (iOS)
import OnairosSDK
// 1. Initialize SDK
Task {
try await OnairosSDK.shared.initializeWithApiKey("your_api_key")
}
// 2. Add connect button
let button = OnairosSDK.shared.createConnectButton { result in
switch result {
case .success(let data):
print("API URL: \(data.apiURL)")
print("Token: \(data.token)")
print("Platforms: \(data.connectedPlatforms.keys)")
case .failure(let error):
print("Error: \(error)")
}
}
view.addSubview(button)
React Native
import { OnairosButton, initializeApiKey } from '@onairos/react-native';
// 1. Initialize SDK
await initializeApiKey({ apiKey: 'your_api_key' });
// 2. Add connect button
<OnairosButton
AppName="YourApp"
onResolved={(data) => {
console.log('API URL:', data.apiURL);
console.log('Token:', data.token);
}}
requestData={{
personality_traits: {
name: "Personality Analysis",
description: "AI analysis for personalization",
reward: "Better recommendations"
}
}}
/>
Flutter
import 'package:onairos/onairos.dart';
// Add connect button
OnairosButtonWrapper1(
webpageName: 'YourApp',
requestData: {
"personality_traits": {
"name": "Personality Analysis",
"description": "AI analysis for personalization",
"reward": "Better recommendations"
}
},
returnLink: 'yourapp://callback',
autoFetch: true,
onResolved: (apiUrl, token) {
print('API URL: $apiUrl');
print('Token: $token');
},
)
Configuration
Swift
// Production
let config = OnairosConfig(
apiKey: "your_api_key",
environment: .production,
platforms: [.youtube, .reddit, .chatgpt, .pinterest],
googleClientID: "your-google-client-id", // For YouTube
urlScheme: "your-app-scheme",
appName: "Your App"
)
OnairosSDK.shared.initialize(config: config)
// Test Mode (for development - no API calls)
let testConfig = OnairosConfig.testMode(
urlScheme: "your-app-scheme",
appName: "Your App"
)
OnairosSDK.shared.initialize(config: testConfig)
Platform Customization (Swift)
Control which platforms appear on the connection screen and which get the "Highly Recommended" badge:
let config = OnairosConfig(
apiKey: "your_api_key",
environment: .production,
// Only show these platforms on the connect screen
platforms: [.youtube, .chatgpt, .reddit],
// These platforms will show a "Highly Recommended" badge
recommendedPlatforms: [.youtube, .chatgpt],
googleClientID: "your-google-client-id",
urlScheme: "your-app-scheme",
appName: "Your App"
)
OnairosSDK.shared.initialize(config: config)
Available Platforms
| Platform | Enum Value | Auth Type |
|---|---|---|
| YouTube | .youtube | Google Sign-In SDK |
| ChatGPT | .chatgpt | WebView Login |
.reddit | OAuth | |
.linkedin | OAuth | |
.pinterest | OAuth | |
| Gmail | .gmail | OAuth |
| X (Twitter) | .x | OAuth |
| Claude | .claude | WebView Login |
| Gemini | .gemini | WebView Login |
| Grok | .grok | WebView Login |
If you don't specify platforms, all available platforms will be shown. If you don't specify recommendedPlatforms, YouTube and ChatGPT will be marked as recommended by default.
React Native / Flutter
// React Native
<OnairosButton
debug={true} // Enable logging
testMode={true} // Bypass API calls for testing
auto={true} // Auto-fetch data on consent
// ...
/>
Platform Authentication (iOS)
YouTube Setup
Add to Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.YOUR_CLIENT_ID</string>
</array>
</dict>
</array>
Add to AppDelegate.swift:
import OnairosSDK
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return YouTubeAuthManager.shared.handleURL(url)
}
OAuth Platforms (Reddit, Pinterest, Gmail)
Add custom URL scheme to Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>your-app-scheme</string>
</array>
</dict>
</array>
Handling the Response
After onboarding, you receive an API URL and token to fetch user data.
Swift
func handleSuccess(_ data: OnboardingData) {
var request = URLRequest(url: URL(string: data.apiURL)!)
request.httpMethod = "POST"
request.setValue("Bearer \(data.token)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let input: [String: Any] = [
"Input": [
"item1": ["text": "Product description", "category": "fashion"]
]
]
request.httpBody = try? JSONSerialization.data(withJSONObject: input)
URLSession.shared.dataTask(with: request) { data, _, _ in
// Handle inference results
}.resume()
}
React Native / Flutter
// React Native
const handleComplete = async (data) => {
const response = await fetch(data.apiURL, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + data.token,
'Content-Type': 'application/json'
},
body: JSON.stringify({
Input: { item1: { text: "Product", category: "fashion" } }
})
});
const result = await response.json();
};
// Flutter
Future<void> onResolved(String apiUrl, String token) async {
final response = await http.post(
Uri.parse(apiUrl),
headers: {
"Authorization": "Bearer $token",
"Content-Type": "application/json",
},
body: jsonEncode({
"Input": {"item1": {"text": "Product", "category": "fashion"}}
}),
);
}
Session Management (Swift)
// Check for existing session
if OnairosSDK.shared.hasExistingSession() {
// User already onboarded
} else {
// Show onboarding
OnairosSDK.shared.presentOnboarding(from: self) { result in
// Handle result
}
}
// Logout
OnairosSDK.shared.clearSession()
Error Handling
Swift
case .failure(let error):
switch error {
case .networkUnavailable:
showAlert("Check your internet connection")
case .userCancelled:
// User dismissed the modal
case .configurationError(let msg):
showAlert("Config error: \(msg)")
default:
showAlert(error.localizedDescription)
}
React Native
onError={(error) => {
if (error.code === 'USER_CANCELLED') {
// User dismissed
} else if (error.code === 'NETWORK_ERROR') {
Alert.alert('Check your connection');
}
}}
SwiftUI Example
import SwiftUI
import OnairosSDK
struct ContentView: View {
@State private var result: OnboardingData?
var body: some View {
VStack {
OnairosButtonView { res in
if case .success(let data) = res {
result = data
}
}
if let data = result {
Text("Connected: \(data.connectedPlatforms.keys.joined(separator: ", "))")
}
}
.onAppear {
Task {
try? await OnairosSDK.shared.initializeWithApiKey("your_key")
}
}
}
}
struct OnairosButtonView: UIViewRepresentable {
let completion: (Result<OnboardingData, OnairosError>) -> Void
func makeUIView(context: Context) -> UIButton {
OnairosSDK.shared.createConnectButton { result in
if case .success(.success(let data)) = result {
completion(.success(data))
}
}
}
func updateUIView(_ uiView: UIButton, context: Context) {}
}
Troubleshooting
| Issue | Solution |
|---|---|
| YouTube auth fails (iOS) | Check URL scheme matches Google client ID in Info.plist |
| OAuth callback not working | Verify URL scheme and AppDelegate handling |
| Modal won't dismiss | Use test mode during development |
| Network errors | Check connectivity, enable debug logging |
Contact support@onairos.uk or join Discord.