Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version 1.3.0 #80

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ captures
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
.kotlin
.kotlin
firebase/
66 changes: 66 additions & 0 deletions firebase_push_notification_sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import json
import requests
import google.auth.transport.requests
from google.oauth2 import service_account

PROJECT_ID = '' #find it in firebase -> project settings -> General
SERVICE_ACCOUNT_FILE = 'service_account.json' #Download service account service file from project settings -> Service Accounts -> Generate new private key

FCM_API_URL = f"https://fcm.googleapis.com/v1/projects/{PROJECT_ID}/messages:send" # DON'T CHANGE THIS
SCOPES = ['https://www.googleapis.com/auth/firebase.messaging'] # DON'T CHANGE THIS


def test_send_data_and_notification_message():
token = ""
data = {'key1': 'value2', 'key2': 'value2'}
title = "Test Notification Title from FCM"
body = "Test Notification Body message from FCM"
response = send_data_and_notification_message(token, title, body, data)
if response.status_code == 200:
print("Message sent successfully")
else:
print("Error sending message:", response.text)


def get_access_token():
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials.token

def send_data_and_notification_message(token, title, body, data):
access_token = get_access_token()
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
message = {
"message": {
"token": token,
'notification': {
'title': title,
'body': body
},
"data": data,
"apns": {
"headers": {
"apns-priority": "10"
},
"payload": {
"aps": {
"badge": 0,
# "content-available": 1
},
}
}
}
}
response = requests.post(FCM_API_URL, headers=headers, data=json.dumps(message))
return response


def main():
test_send_data_and_notification_message()

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kotlin.mpp.enableCInteropCommonization=true
#Development
development=true

kmpNotifierVersion=1.2.1
kmpNotifierVersion=1.3.0
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[versions]
compose = "1.6.8"
compose = "1.7.2"
compose-plugin = "1.6.11"
agp = "8.2.2"
android-minSdk = "21"
android-compileSdk = "34"
android-targetSdk = "34"
androidx-activityCompose = "1.9.1"
androidx-activityCompose = "1.9.2"
androidx-core-ktx = "1.13.1"
androidx-appcompat = "1.7.0"
androidx-material = "1.12.0"
androidx-constraintlayout = "2.1.4"
androidx-test-junit = "1.2.1"
androidx-espresso-core = "3.6.1"
androidx-startup-runtime = "1.1.1"
kotlin = "2.0.0"
androidx-startup-runtime = "1.2.0"
kotlin = "2.0.20"
junit = "4.13.2"
koin = "4.0.0-RC1"
koin = "4.0.0"
kotlinx-binary-validator = "0.13.2"
dokka = "1.9.10"
firebase-messaging = "24.0.0"
kotlinx-coroutine = "1.9.0-RC"
firebase-messaging = "24.0.1"
kotlinx-coroutine = "1.9.0-RC.2"
nexusPublish = "2.0.0"


Expand Down
1 change: 1 addition & 0 deletions kmpnotifier/api/android/kmpnotifier.api
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public final class com/mmk/kmpnotifier/extensions/NotifierManagerExtKt {
public static final fun initialize (Lcom/mmk/kmpnotifier/notification/NotifierManager;Landroid/content/Context;Lcom/mmk/kmpnotifier/notification/configuration/NotificationPlatformConfiguration;)V
public static final fun onCreateOrOnNewIntent (Lcom/mmk/kmpnotifier/notification/NotifierManager;Landroid/content/Intent;)V
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.mmk.kmpnotifier.extensions

import android.content.Context
import android.content.Intent
import androidx.core.os.bundleOf
import com.mmk.kmpnotifier.Constants.ACTION_NOTIFICATION_CLICK
import com.mmk.kmpnotifier.Constants.KEY_ANDROID_FIREBASE_NOTIFICATION
import com.mmk.kmpnotifier.di.ContextInitializer
import com.mmk.kmpnotifier.notification.NotifierManager
import com.mmk.kmpnotifier.notification.NotifierManagerImpl
import com.mmk.kmpnotifier.notification.configuration.NotificationPlatformConfiguration
Expand Down Expand Up @@ -56,6 +58,23 @@ public fun NotifierManager.onCreateOrOnNewIntent(intent: Intent?) {
NotifierManagerImpl.onNotificationClicked(payloadData.minus(ACTION_NOTIFICATION_CLICK))
}


/**
* @param context Android application context. By default
* using androidx-startup Context reference is passed without needing to pass one manually.
* If you disabled androidx-startup you can use this function in android application start to pass Context reference
* @param configuration pass android configuration
* @see NotificationPlatformConfiguration.Android
*
*/
public fun NotifierManager.initialize(
context: Context,
configuration: NotificationPlatformConfiguration
) {
ContextInitializer().create(context)
NotifierManagerImpl.initialize(configuration)
}

internal fun NotifierManagerImpl.shouldShowNotification(): Boolean {
val configuration =
NotifierManagerImpl.getConfiguration() as? NotificationPlatformConfiguration.Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fun App() {
}
})
myPushNotificationToken = NotifierManager.getPushNotifier().getToken() ?: ""
println("Firebase Token: $myPushNotificationToken")
}


Expand Down
Loading