Developer Documentation
Integrate Blaink SDK into your iOS and Android applications with our comprehensive guides and code examples.
iOS Integration
Get started with Blaink SDK for iOS in just a few simple steps. Our SDK is designed to be lightweight and easy to integrate.
Add Swift Package to Your Project
Add the Blaink SDK to your Xcode project using Swift Package Manager:
// 1. Open your Xcode project
// 2. Go to File β Swift Packages β Add Package Dependency...
// 3. Enter the repository URL:
https://github.com/Rashidium/blainks-ios.git
Initialize the SDK in AppDelegate
Set up the Blaink SDK in your AppDelegate to configure push notifications and initialize the SDK:
import UIKit
import Blaink
import UserNotifications
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// MARK: - Properties
let blaink = Blaink()
// MARK: - Application Lifecycle
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Request permission for push notifications
Task {
do {
let granted = try await UNUserNotificationCenter.current().requestAuthorization(
options: [.alert, .sound, .badge]
)
if granted {
await MainActor.run {
application.registerForRemoteNotifications()
}
}
} catch {
print("Failed to request notification authorization: \(error.localizedDescription)")
}
}
// Configure Blaink SDK based on build configuration
#if DEBUG
blaink.setup(
sdkKey: "TEST_SDK_KEY",
environment: .development,
isDebugLogsEnabled: true
)
#else
blaink.setup(sdkKey: "PRODUCTION_SDK_KEY")
#endif
// Set delegate for handling notifications
blaink.delegate = self
return true
}
}
Pass Device Token to the SDK
Implement the device token registration method to enable push notifications:
// MARK: - Remote Notifications
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// Pass the device token to Blaink SDK
blaink.registerForRemoteNotificationsWithDeviceToken(deviceToken)
}
Implement BlainkDelegate Methods
Extend your AppDelegate to handle incoming notifications and retrieve the Blaink user ID:
// MARK: - BlainkDelegate
extension AppDelegate: BlainkDelegate {
/// Called when a notification is received
/// - Parameter notification: The notification payload
func didReceiveNotification(_ notification: [AnyHashable: Any]) {
// Handle notification received with payload
// Implement custom deep link handling if needed
print("Received notification: \(notification)")
// Example: Handle custom deep link
if let deepLink = notification["deep_link"] as? String {
handleDeepLink(deepLink)
}
}
/// Called when successfully registered for Blaink notifications
/// - Parameter blainkUserId: Your unique Blaink user ID
func didRegisterForBlainkNotifications(blainkUserId: String) {
// Store the Blaink user ID for sending notifications
// Submit to your backend if you have custom notification logic
print("Registered for Blaink notifications with user ID: \(blainkUserId)")
// Example: Send user ID to your backend
sendUserIdToBackend(blainkUserId)
}
}
// MARK: - Helper Methods
private extension AppDelegate {
func handleDeepLink(_ deepLink: String) {
// Implement your deep link handling logic
print("Handling deep link: \(deepLink)")
}
func sendUserIdToBackend(_ userId: String) {
// Implement your backend integration
print("Sending user ID to backend: \(userId)")
}
}
Additional Configuration
π± Required Permissions
Make sure to add the following capabilities to your project:
- Remote Push Notifications - Required for receiving notifications
- Background App Refresh - Optional, for background processing
π§ Build Configuration
Use different SDK keys for development and production environments:
- Development: Use test keys for development builds
- Production: Use production keys for App Store builds
Android Integration
Get started with Blaink SDK for Android in just a few simple steps. Our SDK integrates seamlessly with Firebase Cloud Messaging.
Add SDK through Gradle
Add the required repositories to your project's build.gradle file:
maven { url = uri("https://jitpack.io") }
// Add GitHub Packages repository
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Blaink/blaink-android")
}
Add google-services.json to Project
Place the google-services.json file obtained from your Firebase project in the app directory of your project.
Register SDK in Application Class
Create or modify your Application class to initialize the Blaink SDK:
class SampleApplication : Application(), BlainkDelegate {
override fun onCreate() {
super.onCreate()
// Initialize Blaink SDK
val blaink = Blaink.getInstance()
blaink.delegate = this
blaink.setup(
context = this,
sdkKey = "TEST_SDK_KEY",
environment = PushEnvironment.DEVELOPMENT,
isDebugLogsEnabled = true
)
}
}
Listen for Notifications and Blaink User ID
Implement the delegate methods to handle notifications:
override fun didReceiveNotification(notification: Map) {
// Handle notification received
println("π± Notification received: $notification")
}
override fun didRegisterForBlainkNotifications(blainkUserId: String) {
// Handle successful registration
println("β
Registered for Blaink notifications with user ID: $blainkUserId")
}
Request Permissions in Main Activity
In your main activity, request permissions and register for push notifications:
private val blaink = Blaink.getInstance()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Get FCM token and register with Blaink
setupPushNotifications()
}
private fun setupPushNotifications() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),
101
)
}
}
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (!task.isSuccessful) {
println("β Fetching FCM registration token failed: task.exception")
return@addOnCompleteListener
}
// Get new FCM registration token
val token = task.result
println("π FCM Token: $token")
// Register token with Blaink
blaink.registerForRemoteNotifications(token)
Toast.makeText(this, "FCM token registered with Blaink", Toast.LENGTH_SHORT).show()
}
}
private fun testLogout() {
lifecycleScope.launch {
val result = blaink.logout()
if (result.isSuccess) {
Toast.makeText(this@MainActivity, "Logged out successfully", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this@MainActivity, "Logout failed: result.exceptionOrNull()?.message", Toast.LENGTH_LONG).show()
}
}
}
Add Permissions to Manifest
Add the necessary permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
Register Blaink Services
Add the Blaink services to your AndroidManifest.xml:
<!-- Blaink FCM Service -->
<service
android:name="com.blaink.push.BlainkFCMService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.blaink.push.NotificationDismissService"
android:exported="false" />
Additional Configuration
π± Required Dependencies
Make sure to add the following dependencies to your app's build.gradle:
- Firebase BOM - For Firebase Cloud Messaging
- Blaink SDK - Core SDK functionality
π§ Build Configuration
Use different SDK keys for development and production environments:
- Development: Use test keys for development builds
- Production: Use production keys for Play Store builds
Need Help?
Our team is here to help you integrate Blaink SDK successfully. Get in touch with us for support and guidance.