Remote Notification Manager for Kotlin Multiplatform Mobile iOS and android

Overview

abc-kmm-notifications: Remote Notification Manager

Kotlin KMM AGP Gradle Platform

Remote Notification Manager for Kotlin Multiplatform Mobile

Features

  • Super easy to use APNs and FCM in one interface
  • Dramatically reduce code to write
  • Support for generic model mapping
  • Support FCM for iOS
  • Migration Support for React Native

Requirements

  • iOS
    • Deployment Target 10.0 or higher
  • Android
    • minSdkVersion 21

Installation

Gradle Settings

Add below gradle settings into your KMP (Kotlin Multiplatform Project)

build.gradle.kts in root

buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.0.1")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
        classpath("org.jetbrains.kotlin:kotlin-serialization:1.5.21")
        classpath("com.google.gms:google-services:4.3.5")
    }
}

build.gradle.kts in shared

() .forEach { it.transitiveExport = true it.export(abcNotifications) } } android() val commonMain by getting { dependencies { implementation(abcNotifications) implementation(kotlinxSerialization) } } val androidMain by getting { dependencies { implementation(abcNotifications) api(abcNotifications) } } val iosMain by getting { dependencies { implementation(abcNotifications) api(abcNotifications) } } } } ">
plugins {
    id("com.android.library")
    kotlin("multiplatform")
    kotlin("plugin.serialization")
}

val abcNotifications = "com.linecorp.abc:kmm-notifications:0.4.1"
val kotlinxSerialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"

kotlin {
    sourceSets {
        ios {
            binaries
                .filterIsInstance<Framework>()
                .forEach {
                    it.transitiveExport = true
                    it.export(abcNotifications)
                }
        }
        android()

        val commonMain by getting {
            dependencies {
                implementation(abcNotifications)
                implementation(kotlinxSerialization)
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(abcNotifications)
                api(abcNotifications)
            }
        }
        val iosMain by getting {
            dependencies {
                implementation(abcNotifications)
                api(abcNotifications)
            }
        }
    }
}

build.gradle.kts in androidApp

plugins {
    id("com.google.gms.google-services")
}

Usage

Definition of payload and map function with generic in commonMain of your project

() ">
@Serializable
data class Data(
  val notificationType: String = "",
  val id: Int = 0,
)

@Throws(Throwable::class)
fun NotificationElement.payload() = decodedPayload<Data>()

Android

ABCNotifications
    .onNewToken(this) {
        // TODO: send to register ${ABCDeviceToken.value} to server
    }
    .onDeletedMessages(this) {
        // TODO: sync messages to server
    }
    .onMessageReceived(this) {
        // FCM RemoteMessage
        val remoteMessage = it.remoteMessage
        
        // decode to Payload with Data
        val payload = it.payload()

        // decode to Data
        val data = it.decodedData<Data>()

        // TODO: present a dialog for push notification
    }
    .beginListening()

iOS

ABCNotifications.Companion()
    .registerSettings {
        $0.add(type: .alert)
        $0.add(type: .badge)
        $0.add(type: .sound)
    }
    .onNewToken(target: self) {
        // TODO: send to register ${ABCDeviceToken.rawValue} to server
    }
    .onMessageReceived(target: self) {
        guard let payload = try? $0.payload() else { return }

        if $0.isInactive {
            // TODO: present a view controller on inactive
        } else {
            // TODO: present a toast message on active
        }
    }.beginListening()

Required implementation in AppDelegate

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ABCNotificationCenterDelegate.Companion().applicationDidFinishLaunching(options: options)
        return true
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        ABCNotificationCenterDelegate.Companion().applicationDidRegisterForRemoteNotifications(deviceToken: deviceToken)
    }
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        ABCNotificationCenterDelegate.Companion().userNotificationCenterWillPresent(notification: notification)
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        ABCNotificationCenterDelegate.Companion().userNotificationCenterDidReceive(response: response)
    }
}

FCM on iOS

  1. Insert the dependency in shared.podspec

    spec.dependency 'FirebaseMessaging'
  2. Insert function into cocoapods definition in build.gradle.kts (shared)

    cocoapods {
        noPodspec()
    }
  3. Initializing

    ", ABCDeviceToken.Companion().FCMToken) // TODO: send to register ${ABCDeviceToken.FCMToken} to server }.beginListening() ">
    ABCNotifications.Companion()
        .allowsFCMOnIOS()
        .registerSettings {
            $0.add(type: .alert)
            $0.add(type: .badge)
            $0.add(type: .sound)
        }
        .onNewToken(target: self) {
            print("onNewToken -> ", ABCDeviceToken.Companion().FCMToken)
            // TODO: send to register ${ABCDeviceToken.FCMToken} to server
        }.beginListening()

Advanced

Shared configuration in commonMain

fun ABCNotifications.Companion.configure(block: ABCNotifications.Companion.() -> Unit) {
    apply(block)

    onNewToken(this) {
        // TODO: send to register ${ABCDeviceToken.value} to server
    }.beginListening()
}

Android

ABCNotifications.configure {
    onDeletedMessages(this) {
        // TODO: sync messages to server
    }
    onMessageReceived(this) {
        // FCM RemoteMessage
        val remoteMessage = it.remoteMessage

        // decode to Payload with Data
        val payload = it.payload()

        // decode to Data
        val data = it.decodedData<Data>()

        // TODO: present a dialog for push notification
    }
}

iOS

ABCNotifications.Companion().configure { [unowned self] in
    $0.registerSettings {
        $0.add(type: .alert)
        $0.add(type: .badge)
        $0.add(type: .sound)
    }
    $0.onMessageReceived(target: self) {
        guard let payload = try? $0.payload() else { return }

        if $0.isInactive {
            // TODO: present a view controller on inactive
        } else {
            // TODO: present a toast message on active
        }
    }
}
You might also like...
Floating Notification for Android app - Facebook ChatHeads Notification system

FloatingView (Application Demo on Play Store) DEPRECATED SEE FloatingView Floating View for Android app - Facebook ChatHeads Notification system This

Pull Notification 0.8 0.0 Java Notification TO GO
Pull Notification 0.8 0.0 Java Notification TO GO

Full FCM Push/Pull Notification Featured In : Index Overview Features Prerequisites Usage Notes License Overview FCM push/pull notification is a libra

Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development
Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin widgets This is a Kotlin MultiPlatform library that provides declarative UI and application screens management in common code. You can i

The idea of ResideMenu is from Dribbble 1 and 2. It has come true and run in iOS devices. iOS ResideMenu This project is the RefsideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. And thanks to the authors for the above idea and contribution. An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.
An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.

ShortcutBadger: The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! Supported launchers: Sony

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.
An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile. 项目架构主要分为原生系统层、Android/iOS业务SDK层、KMM SDK层、KMM业务逻辑SDK层、iOS sdkfra

Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures
Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures

CatViewerDemo Android demo iOS demo Kotlin Multiplatform Mobile demo for Android and iOS. App for viewing Cat pictures from Cats API. This sample show

Analytics Tools for Kotlin Multiplatform Mobile iOS and android
Analytics Tools for Kotlin Multiplatform Mobile iOS and android

Index Features Example Introduce Architecture Installation Configure Using Screen Mapper Initialization Implementation Delegate Parameters ATEventPara

A local storage management library for Kotlin Multiplatform Mobile iOS and android
A local storage management library for Kotlin Multiplatform Mobile iOS and android

A local storage management library for Kotlin Multiplatform Mobile iOS and android Features iOS and Android local storage in one interface Provides ge

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

iOS(iPhone & iPad) and Android Radio/Podcast Streaming Apps built in Kotlin Multiplatform Mobile (KMM) with SwiftUI & Jetpack Compose
iOS(iPhone & iPad) and Android Radio/Podcast Streaming Apps built in Kotlin Multiplatform Mobile (KMM) with SwiftUI & Jetpack Compose

iOS(iPhone & iPad) and Android Radio/Podcast Streaming Apps built in Kotlin Multiplatform Mobile (KMM) with SwiftUI & Jetpack Compose

 StackExpandableView - A custom view that resembles the iOS notification group behavior
StackExpandableView - A custom view that resembles the iOS notification group behavior

StackExpandableView - A custom view that resembles the iOS notification group behavior

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin Model-View-ViewModel architecture components This is a Kotlin Multiplatform library that provides architecture components of Model-View-

Ethereum Web3 implementation for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin web3 This is a Kotlin MultiPlatform library that ... Table of Contents Features Requirements Installation Usage Samples Set Up Locally C

🍭 GithubSearchKMM - Github Repos Search - Android - iOS - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Dependency Injection, shared KMP ViewModel, Clean Architecture
🍭 GithubSearchKMM - Github Repos Search - Android - iOS - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Dependency Injection, shared KMP ViewModel, Clean Architecture

GithubSearchKMM Github Repos Search - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Depend

Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

KMM RSS Reader: an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile.
KMM RSS Reader: an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile.

KMM RSS Reader This is an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile. It's a simple RSS reader, and you ca

Attendance-Manager - Attendance Manager, a attendance recording app that helps stay at your 75% attendance
Attendance-Manager - Attendance Manager, a attendance recording app that helps stay at your 75% attendance

Android-Study-Jams Attendance tracker app Problem Statement: There has been a ne

Gradle plugin that generates a Swift Package Manager manifest and an XCFramework to distribute a Kotlin Multiplatform library for Apple platforms.

Multiplatform Swift Package This is a Gradle plugin for Kotlin Multiplatform projects that generates an XCFramework for your native Apple targets and

Comments
  • Could not resolve com.linecorp.abc:kmm-notifications:0.4.1

    Could not resolve com.linecorp.abc:kmm-notifications:0.4.1

    Hey! i am trying to use the latest version of kmm-notifications everything is work in common main and android main but when i try to add the dependency to ios main its not unable to resolve.

    here is the code for my build.gradle file.

    plugins {
        kotlin("multiplatform")
        kotlin("native.cocoapods")
        kotlin(KotlinPlugins.serialization) version Kotlin.version
        id("com.android.library")
    
    }
    
    version = "1.0"
    val abcNotifications = "com.linecorp.abc:kmm-notifications:0.4.1"
    kotlin {
        android()
        iosX64()
        iosArm64()
        iosSimulatorArm64()
    
    
    
        cocoapods {
            summary = "Some description for the Shared Module"
            homepage = "Link to the Shared Module homepage"
            ios.deploymentTarget = "14.1"
            podfile = project.file("../markazSupplierIos/Podfile")
    
            framework {
                baseName = "shared"
            }
        }
    
        sourceSets {
    
            val commonMain by getting {
                dependencies {
                    implementation(Ktor.core)
                    implementation(Ktor.clientSerialization)
                    implementation(Kotlinx.datetime)
                    implementation(Koin.koin)
                    implementation(Ktor.ktorLogging)
                    implementation(Firebase.auth)
                    implementation(MultiplatformSettings.core)
                    implementation(MultiplatformSettings.coroutines)
                    implementation(abcNotifications)
                    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1-native-mt")
                    implementation("io.islandtime:core:0.6.3")
    
    
                }
            }
            val androidMain by getting {
                dependencies {
                    implementation(Ktor.android)
                    implementation(Koin.koinAndroid)
                    implementation(Ktor.androidLogging)
                    runtimeOnly(Ktor.okhttp)
                    implementation(Datastore.datastore)
                    implementation(abcNotifications)
                    api(abcNotifications)
                    implementation(MultiplatformSettings.datastore)
    
                }
            }
            val commonTest by getting {
                dependencies {
                    implementation(kotlin("test"))
    
                }
            }
    
    
            val androidTest by getting
            val iosX64Main by getting
            val iosArm64Main by getting
            val iosSimulatorArm64Main by getting
            val iosMain by creating {
                dependencies {
                    implementation(Ktor.ios)
    
                    implementation(abcNotifications)
                    api(abcNotifications)
    
    
                }
                dependsOn(commonMain)
                iosX64Main.dependsOn(this)
                iosArm64Main.dependsOn(this)
                iosSimulatorArm64Main.dependsOn(this)
            }
            val iosX64Test by getting
            val iosArm64Test by getting
            val iosSimulatorArm64Test by getting
            val iosTest by creating {
                dependsOn(commonTest)
                iosX64Test.dependsOn(this)
                iosArm64Test.dependsOn(this)
                iosSimulatorArm64Test.dependsOn(this)
            }
        }
    }
    
    android {
        compileSdk = 31
        sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
        defaultConfig {
            minSdk = 21
            targetSdk = 31
        }
    }
    

    here is the message i am getting

    Could not resolve com.linecorp.abc:kmm-notifications:0.4.1
    
    Could not resolve com.linecorp.abc:kmm-notifications:0.4.1.
    Required by:
        project :shared
    
    Possible solution:
     - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
    
    

    Any help will be appreciated

    opened by Kashif-E 0
Releases(0.4.1)
Owner
LINE
LINE
Pulls notifications from a remote JSON file and shows them in your app.

android-remote-notifications A Google GCM/Amazon SNS alternative using pull instead of push. Main features Independent user notifications (no Google G

Kai Winter 97 Dec 23, 2022
An android app to display meaning for selected word as notification

Notification Dictionary An Android application to display meaning of selected word as a notification. Features Easy access from all apps that have tex

Karthikeyan Singaravelan 25 Nov 22, 2022
PPNS(public-push-notification-service) for android SDK

Public Push Notification Service - PPNS What is PPNS? It's a cross-platform messaging solution that lets you reliably send messages for free. Inspired

A-big-fish-in-a-small-pond 3 Jul 21, 2022
FCM : FirePush is a lightweight Kotlin/Android library to send FCM push notifications to Android, iOS & Web like a pro.

FirePush - A Lightweight Kotlin Library for sending FCM push notification Hi, I made this Library for a Chat based project I was working on. So I deci

Karandeep Atwal 45 Nov 26, 2022
Way to set heartbeat interval and the User receive PushNotifications from GCM. Based on related post in Google Forums about HeartBeat problem.

AndroidHeartBeatFixer Way to set heartbeat interval and the User receive PushNotifications from GCM. Based on a Google Forums post about HeartBeat pro

João Pedro Nardari dos Santos 58 Jun 15, 2021
Tsunami - An open-source SMS & Call flooding Android application with unlimited OTP bombing capability

An open-source OTP & Call flooding android application with unlimited sending capability

Utsanjan 83 Jan 2, 2023
Android app to search for covid vaccine slots, turn on background search & get notifications when slots are available

CowinNotifier Android app to search for covid vaccine slots, turn on background search & get notifications when slots are available Glipmse of the App

Ujjwal Kumar Maharana 3 Dec 29, 2022
Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Location Service Manager for Kotlin Multiplatform Mobile iOS and android Features Provides simple permission settings Dramatically reduce the amount o

LINE 55 Dec 10, 2022
Optimize notification icons for ColorOS and adapt to native notification icon specifications

Optimize notification icons for ColorOS and adapt to native notification icon specifications

Fankesyooni 23 Jan 4, 2023
Floating Notification for Android app - Facebook ChatHeads Notification system

FloatingView (Application Demo on Play Store) DEPRECATED SEE FloatingView Floating View for Android app - Facebook ChatHeads Notification system This

Fernandez Anthony 530 Nov 17, 2022