-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Receiving Data payload Notification type is implemented (#5)
*Push Notification Data Payload handling *Updating sample code *Updating documentation
- Loading branch information
1 parent
0715729
commit 65b698d
Showing
21 changed files
with
237 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
kmpnotifier/src/androidMain/kotlin/com/mmk/kmpnotifier/extensions/NotifierManagerExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.mmk.kmpnotifier.extensions | ||
|
||
import android.content.Intent | ||
import androidx.core.os.bundleOf | ||
import com.mmk.kmpnotifier.notification.NotifierManager | ||
import com.mmk.kmpnotifier.notification.NotifierManagerImpl | ||
|
||
|
||
/*** | ||
* In order to receive notification data payload this functions needs to be called in | ||
* Android side in launcher Activity #onCreate and #onNewIntent methods. | ||
* | ||
* Example: | ||
* | ||
* ``` | ||
* class MainActivity : ComponentActivity() { | ||
* override fun onCreate(savedInstanceState: Bundle?) { | ||
* super.onCreate(savedInstanceState) | ||
* NotifierManager.onCreateOrOnNewIntent(intent) | ||
* setContent { | ||
* App() | ||
* } | ||
* } | ||
* | ||
* override fun onNewIntent(intent: Intent?) { | ||
* super.onNewIntent(intent) | ||
* NotifierManager.onCreateOrOnNewIntent(intent) | ||
* } | ||
* | ||
* } | ||
* | ||
* ``` | ||
*/ | ||
public fun NotifierManager.onCreateOrOnNewIntent(intent: Intent?) { | ||
if (intent == null) return | ||
val extras = intent.extras ?: bundleOf() | ||
val payloadData = mutableMapOf<String, Any>() | ||
extras.keySet().forEach { key -> | ||
val value = extras.get(key) | ||
value?.let { payloadData[key] = value } | ||
} | ||
if (extras.containsKey("google.sent_time")) NotifierManagerImpl.onPushPayloadData(payloadData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
kmpnotifier/src/commonMain/kotlin/com/mmk/kmpnotifier/notification/PushNotifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
kmpnotifier/src/iosMain/kotlin/com/mmk/kmpnotifier/extensions/NotifierManagerExt.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mmk.kmpnotifier.extensions | ||
|
||
import com.mmk.kmpnotifier.notification.NotifierManager | ||
import com.mmk.kmpnotifier.notification.NotifierManagerImpl | ||
|
||
/*** | ||
* In order to receive notification data payload this functions needs to be called in | ||
* ios Swift side application didReceiveRemoteNotification function | ||
* | ||
* Example: | ||
* | ||
* ``` | ||
* func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult { | ||
* NotifierManager.shared.onApplicationDidReceiveRemoteNotification(userInfo: userInfo) | ||
* return UIBackgroundFetchResult.newData | ||
* } | ||
* ``` | ||
*/ | ||
public fun NotifierManager.onApplicationDidReceiveRemoteNotification(userInfo:Map<Any?, *>){ | ||
val payloadData = userInfo.keys | ||
.filterNotNull() | ||
.filterIsInstance<String>() | ||
.associateWith { key -> userInfo[key] } | ||
|
||
if (payloadData.containsKey("gcm.message_id")) NotifierManagerImpl.onPushPayloadData(payloadData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
sample/src/androidMain/kotlin/com/mmk/kmpnotifier/sample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
sample/src/androidMain/kotlin/com/mmk/kmpnotifier/sample/MainApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mmk.kmpnotifier.sample | ||
|
||
import android.app.Application | ||
import com.mmk.kmpnotifier.notification.NotifierManager | ||
import com.mmk.kmpnotifier.notification.PayloadData | ||
import com.mmk.kmpnotifier.notification.configuration.NotificationPlatformConfiguration | ||
|
||
class MainApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
AppInitializer.onApplicationStart() | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
sample/src/androidMain/kotlin/com/mmk/kmpnotifier/sample/Platform.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mmk.kmpnotifier.sample | ||
|
||
import com.mmk.kmpnotifier.notification.NotifierManager | ||
import com.mmk.kmpnotifier.notification.configuration.NotificationPlatformConfiguration | ||
|
||
actual fun onApplicationStartPlatformSpecific() { | ||
NotifierManager.initialize( | ||
configuration = NotificationPlatformConfiguration.Android( | ||
notificationIconResId = R.drawable.ic_launcher_foreground, | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.