Skip to content

Commit

Permalink
[issue-1048] Integrate Onesignal for push notification
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenduythuc committed Oct 5, 2023
1 parent 0d112b0 commit 5938af2
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 133 deletions.
30 changes: 19 additions & 11 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
apply plugin: "com.google.gms.google-services"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

/**
Expand Down Expand Up @@ -115,21 +116,28 @@ android {
}

dependencies {
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
implementation 'com.facebook.fresco:animated-base-support:1.3.0'
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
implementation 'com.facebook.fresco:animated-base-support:1.3.0'

// For animated GIF support
implementation 'com.facebook.fresco:animated-gif:2.5.0'
// For animated GIF support
implementation 'com.facebook.fresco:animated-gif:2.5.0'

// For WebP support, including animated WebP
implementation 'com.facebook.fresco:animated-webp:2.5.0'
implementation 'com.facebook.fresco:webpsupport:2.5.0'
// For WebP support, including animated WebP
implementation 'com.facebook.fresco:animated-webp:2.5.0'
implementation 'com.facebook.fresco:webpsupport:2.5.0'

// Support new Splash Screen API
implementation "androidx.core:core-splashscreen:1.0.0"
// Support new Splash Screen API
implementation "androidx.core:core-splashscreen:1.0.0"

// Fix duplicate Kotlin JDK 7 & JDK 8
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
// Add OneSignal push notification
implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'

// Add Firebase config
implementation platform('com.google.firebase:firebase-bom:32.3.1')


// Fix duplicate Kotlin JDK 7 & JDK 8
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')

// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
Expand Down
29 changes: 29 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "569870677705",
"project_id": "subwallet-app",
"storage_bucket": "subwallet-app.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:569870677705:android:cbc031f789e9677e38ff18",
"android_client_info": {
"package_name": "app.subwallet.mobile"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBePKienltD3ss-ifbPEuoHOQA-OSigkVY"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ buildscript {
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath 'com.google.gms:google-services:4.3.15'
}
}
13 changes: 13 additions & 0 deletions ios/OneSignalNotificationServiceExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>NotificationService</string>
</dict>
</dict>
</plist>
12 changes: 12 additions & 0 deletions ios/OneSignalNotificationServiceExtension/NotificationService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// NotificationService.h
// OneSignalNotificationServiceExtension
//
// Created by Thức Nguyễn Duy on 29/09/2023.
//

#import <UserNotifications/UserNotifications.h>

@interface NotificationService : UNNotificationServiceExtension

@end
40 changes: 40 additions & 0 deletions ios/OneSignalNotificationServiceExtension/NotificationService.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import <OneSignalExtension/OneSignalExtension.h>

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.receivedRequest = request;
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];

/* DEBUGGING: Uncomment the 2 lines below and comment out the one above to ensure this extension is executing
Note, this extension only runs when mutable-content is set
Setting an attachment or action buttons automatically adds this */
// NSLog(@"Running NotificationServiceExtension");
// self.bestAttemptContent.body = [@"[Modified] " stringByAppendingString:self.bestAttemptContent.body];

[OneSignalExtension didReceiveNotificationExtensionRequest:self.receivedRequest
withMutableNotificationContent:self.bestAttemptContent
withContentHandler:self.contentHandler];
}

- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.

[OneSignalExtension serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];

self.contentHandler(self.bestAttemptContent);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.app.subwallet.mobile.onesignal</string>
</array>
</dict>
</plist>
3 changes: 3 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ target 'SubWalletMobile' do
end
end

target 'OneSignalNotificationServiceExtension' do
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end
Loading

0 comments on commit 5938af2

Please sign in to comment.