@trycourier/courier-react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +382 -0
- package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +17 -0
- package/android/.idea/jarRepositories.xml +35 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +149 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/local.properties +8 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +62 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +199 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +19 -0
- package/android/src/main/java/com/courierreactnative/NotificationPermissionStatus.kt +6 -0
- package/courier-react-native.podspec +37 -0
- package/ios/CourierReactNative-Bridging-Header.h +3 -0
- package/ios/CourierReactNative.m +53 -0
- package/ios/CourierReactNative.swift +286 -0
- package/ios/CourierReactNative.xcodeproj/project.pbxproj +283 -0
- package/ios/CourierReactNativeDelegate.h +20 -0
- package/ios/CourierReactNativeDelegate.m +125 -0
- package/lib/commonjs/index.js +305 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +295 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/index.d.ts +140 -0
- package/package.json +156 -0
- package/src/index.ts +337 -0
package/android/gradlew
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2015 the original author or authors.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
##############################################################################
|
|
20
|
+
##
|
|
21
|
+
## Gradle start up script for UN*X
|
|
22
|
+
##
|
|
23
|
+
##############################################################################
|
|
24
|
+
|
|
25
|
+
# Attempt to set APP_HOME
|
|
26
|
+
# Resolve links: $0 may be a link
|
|
27
|
+
PRG="$0"
|
|
28
|
+
# Need this for relative symlinks.
|
|
29
|
+
while [ -h "$PRG" ] ; do
|
|
30
|
+
ls=`ls -ld "$PRG"`
|
|
31
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
32
|
+
if expr "$link" : '/.*' > /dev/null; then
|
|
33
|
+
PRG="$link"
|
|
34
|
+
else
|
|
35
|
+
PRG=`dirname "$PRG"`"/$link"
|
|
36
|
+
fi
|
|
37
|
+
done
|
|
38
|
+
SAVED="`pwd`"
|
|
39
|
+
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
40
|
+
APP_HOME="`pwd -P`"
|
|
41
|
+
cd "$SAVED" >/dev/null
|
|
42
|
+
|
|
43
|
+
APP_NAME="Gradle"
|
|
44
|
+
APP_BASE_NAME=`basename "$0"`
|
|
45
|
+
|
|
46
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
47
|
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
48
|
+
|
|
49
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
50
|
+
MAX_FD="maximum"
|
|
51
|
+
|
|
52
|
+
warn () {
|
|
53
|
+
echo "$*"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
die () {
|
|
57
|
+
echo
|
|
58
|
+
echo "$*"
|
|
59
|
+
echo
|
|
60
|
+
exit 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# OS specific support (must be 'true' or 'false').
|
|
64
|
+
cygwin=false
|
|
65
|
+
msys=false
|
|
66
|
+
darwin=false
|
|
67
|
+
nonstop=false
|
|
68
|
+
case "`uname`" in
|
|
69
|
+
CYGWIN* )
|
|
70
|
+
cygwin=true
|
|
71
|
+
;;
|
|
72
|
+
Darwin* )
|
|
73
|
+
darwin=true
|
|
74
|
+
;;
|
|
75
|
+
MSYS* | MINGW* )
|
|
76
|
+
msys=true
|
|
77
|
+
;;
|
|
78
|
+
NONSTOP* )
|
|
79
|
+
nonstop=true
|
|
80
|
+
;;
|
|
81
|
+
esac
|
|
82
|
+
|
|
83
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Determine the Java command to use to start the JVM.
|
|
87
|
+
if [ -n "$JAVA_HOME" ] ; then
|
|
88
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
89
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
|
90
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
91
|
+
else
|
|
92
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
|
93
|
+
fi
|
|
94
|
+
if [ ! -x "$JAVACMD" ] ; then
|
|
95
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
96
|
+
|
|
97
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
98
|
+
location of your Java installation."
|
|
99
|
+
fi
|
|
100
|
+
else
|
|
101
|
+
JAVACMD="java"
|
|
102
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
103
|
+
|
|
104
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
105
|
+
location of your Java installation."
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
# Increase the maximum file descriptors if we can.
|
|
109
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
|
110
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
|
111
|
+
if [ $? -eq 0 ] ; then
|
|
112
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
113
|
+
MAX_FD="$MAX_FD_LIMIT"
|
|
114
|
+
fi
|
|
115
|
+
ulimit -n $MAX_FD
|
|
116
|
+
if [ $? -ne 0 ] ; then
|
|
117
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
118
|
+
fi
|
|
119
|
+
else
|
|
120
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
121
|
+
fi
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
# For Darwin, add options to specify how the application appears in the dock
|
|
125
|
+
if $darwin; then
|
|
126
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
130
|
+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
131
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
132
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
133
|
+
|
|
134
|
+
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
135
|
+
|
|
136
|
+
# We build the pattern for arguments to be converted via cygpath
|
|
137
|
+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
138
|
+
SEP=""
|
|
139
|
+
for dir in $ROOTDIRSRAW ; do
|
|
140
|
+
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
141
|
+
SEP="|"
|
|
142
|
+
done
|
|
143
|
+
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
144
|
+
# Add a user-defined pattern to the cygpath arguments
|
|
145
|
+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
146
|
+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
147
|
+
fi
|
|
148
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
149
|
+
i=0
|
|
150
|
+
for arg in "$@" ; do
|
|
151
|
+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
152
|
+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
153
|
+
|
|
154
|
+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
155
|
+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
156
|
+
else
|
|
157
|
+
eval `echo args$i`="\"$arg\""
|
|
158
|
+
fi
|
|
159
|
+
i=`expr $i + 1`
|
|
160
|
+
done
|
|
161
|
+
case $i in
|
|
162
|
+
0) set -- ;;
|
|
163
|
+
1) set -- "$args0" ;;
|
|
164
|
+
2) set -- "$args0" "$args1" ;;
|
|
165
|
+
3) set -- "$args0" "$args1" "$args2" ;;
|
|
166
|
+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
167
|
+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
168
|
+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
169
|
+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
170
|
+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
171
|
+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
172
|
+
esac
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# Escape application args
|
|
176
|
+
save () {
|
|
177
|
+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
|
178
|
+
echo " "
|
|
179
|
+
}
|
|
180
|
+
APP_ARGS=`save "$@"`
|
|
181
|
+
|
|
182
|
+
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
|
183
|
+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
184
|
+
|
|
185
|
+
exec "$JAVACMD" "$@"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@rem
|
|
2
|
+
@rem Copyright 2015 the original author or authors.
|
|
3
|
+
@rem
|
|
4
|
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
@rem you may not use this file except in compliance with the License.
|
|
6
|
+
@rem You may obtain a copy of the License at
|
|
7
|
+
@rem
|
|
8
|
+
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
@rem
|
|
10
|
+
@rem Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
@rem See the License for the specific language governing permissions and
|
|
14
|
+
@rem limitations under the License.
|
|
15
|
+
@rem
|
|
16
|
+
|
|
17
|
+
@if "%DEBUG%" == "" @echo off
|
|
18
|
+
@rem ##########################################################################
|
|
19
|
+
@rem
|
|
20
|
+
@rem Gradle startup script for Windows
|
|
21
|
+
@rem
|
|
22
|
+
@rem ##########################################################################
|
|
23
|
+
|
|
24
|
+
@rem Set local scope for the variables with windows NT shell
|
|
25
|
+
if "%OS%"=="Windows_NT" setlocal
|
|
26
|
+
|
|
27
|
+
set DIRNAME=%~dp0
|
|
28
|
+
if "%DIRNAME%" == "" set DIRNAME=.
|
|
29
|
+
set APP_BASE_NAME=%~n0
|
|
30
|
+
set APP_HOME=%DIRNAME%
|
|
31
|
+
|
|
32
|
+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
33
|
+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
34
|
+
|
|
35
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
36
|
+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
37
|
+
|
|
38
|
+
@rem Find java.exe
|
|
39
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
40
|
+
|
|
41
|
+
set JAVA_EXE=java.exe
|
|
42
|
+
%JAVA_EXE% -version >NUL 2>&1
|
|
43
|
+
if "%ERRORLEVEL%" == "0" goto execute
|
|
44
|
+
|
|
45
|
+
echo.
|
|
46
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
47
|
+
echo.
|
|
48
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
49
|
+
echo location of your Java installation.
|
|
50
|
+
|
|
51
|
+
goto fail
|
|
52
|
+
|
|
53
|
+
:findJavaFromJavaHome
|
|
54
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
|
55
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
56
|
+
|
|
57
|
+
if exist "%JAVA_EXE%" goto execute
|
|
58
|
+
|
|
59
|
+
echo.
|
|
60
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
61
|
+
echo.
|
|
62
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
63
|
+
echo location of your Java installation.
|
|
64
|
+
|
|
65
|
+
goto fail
|
|
66
|
+
|
|
67
|
+
:execute
|
|
68
|
+
@rem Setup the command line
|
|
69
|
+
|
|
70
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@rem Execute Gradle
|
|
74
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
75
|
+
|
|
76
|
+
:end
|
|
77
|
+
@rem End local scope for the variables with windows NT shell
|
|
78
|
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
79
|
+
|
|
80
|
+
:fail
|
|
81
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
82
|
+
rem the _cmd.exe /c_ return code!
|
|
83
|
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
84
|
+
exit /b 1
|
|
85
|
+
|
|
86
|
+
:mainEnd
|
|
87
|
+
if "%OS%"=="Windows_NT" endlocal
|
|
88
|
+
|
|
89
|
+
:omega
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## This file must *NOT* be checked into Version Control Systems,
|
|
2
|
+
# as it contains information specific to your local configuration.
|
|
3
|
+
#
|
|
4
|
+
# Location of the SDK. This is only used by Gradle.
|
|
5
|
+
# For customization when using a Version Control System, please read the
|
|
6
|
+
# header note.
|
|
7
|
+
#Thu Oct 27 14:07:52 EDT 2022
|
|
8
|
+
sdk.dir=/Users/mike/Library/Android/sdk
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import com.courier.android.Courier
|
|
6
|
+
import com.courier.android.pushNotification
|
|
7
|
+
import com.courier.android.trackPushNotificationClick
|
|
8
|
+
import com.facebook.react.ReactActivity
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.google.firebase.messaging.RemoteMessage
|
|
11
|
+
import org.json.JSONObject
|
|
12
|
+
|
|
13
|
+
open class CourierReactNativeActivity : ReactActivity() {
|
|
14
|
+
|
|
15
|
+
companion object {
|
|
16
|
+
private const val PUSH_CLICKED_EVENT = "pushNotificationClicked"
|
|
17
|
+
private const val PUSH_DELIVERED_EVENT = "pushNotificationDelivered"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
21
|
+
super.onCreate(savedInstanceState)
|
|
22
|
+
|
|
23
|
+
// Starts the Courier SDK
|
|
24
|
+
// Used to ensure shared preferences works properly
|
|
25
|
+
Courier.initialize(this)
|
|
26
|
+
|
|
27
|
+
// See if there is a pending click event
|
|
28
|
+
checkIntentForPushNotificationClick(intent)
|
|
29
|
+
|
|
30
|
+
// Handle delivered messages on the main thread
|
|
31
|
+
Courier.getLastDeliveredMessage { message ->
|
|
32
|
+
postPushNotificationDelivered(message)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private fun sendEvent(eventName: String, params: String) {
|
|
38
|
+
reactInstanceManager.currentReactContext?.let { reactContext ->
|
|
39
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit(eventName, params)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override fun onNewIntent(intent: Intent?) {
|
|
44
|
+
super.onNewIntent(intent)
|
|
45
|
+
checkIntentForPushNotificationClick(intent)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
49
|
+
intent?.trackPushNotificationClick { message ->
|
|
50
|
+
postPushNotificationClicked(message)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private fun postPushNotificationDelivered(message: RemoteMessage) {
|
|
55
|
+
sendEvent(PUSH_DELIVERED_EVENT, JSONObject(message.pushNotification).toString())
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
59
|
+
sendEvent(PUSH_CLICKED_EVENT, JSONObject(message.pushNotification).toString())
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import com.courier.android.*
|
|
5
|
+
import com.courier.android.models.CourierAgent
|
|
6
|
+
import com.courier.android.models.CourierProvider
|
|
7
|
+
import com.facebook.react.ReactActivity
|
|
8
|
+
import com.facebook.react.bridge.*
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.google.firebase.messaging.RemoteMessage
|
|
11
|
+
import org.json.JSONObject
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
15
|
+
|
|
16
|
+
companion object {
|
|
17
|
+
private const val COURIER_MODULE_NAME = "CourierReactNative"
|
|
18
|
+
private const val COURIER_ERROR_TAG = "Courier Android SDK Error"
|
|
19
|
+
private const val COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT = "courierDebugEvent"
|
|
20
|
+
private const val COURIER_PUSH_NOTIFICATION_CLICKED_EVENT = "pushNotificationClicked"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
init {
|
|
24
|
+
// User Agent is used to ensure we know the SDK
|
|
25
|
+
// the requests come from
|
|
26
|
+
Courier.USER_AGENT = CourierAgent.REACT_NATIVE_ANDROID
|
|
27
|
+
|
|
28
|
+
Courier.shared.logListener = { data ->
|
|
29
|
+
sendEvent(reactContext, COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT, data)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun getName(): String {
|
|
35
|
+
return COURIER_MODULE_NAME
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private val reactActivity: ReactActivity?
|
|
39
|
+
get() = currentActivity as? ReactActivity
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
fun signIn(userId: String, accessToken: String, promise: Promise) {
|
|
43
|
+
Courier.shared.signIn(
|
|
44
|
+
accessToken = accessToken,
|
|
45
|
+
userId = userId,
|
|
46
|
+
onSuccess = {
|
|
47
|
+
promise.resolve(null)
|
|
48
|
+
},
|
|
49
|
+
onFailure = { e ->
|
|
50
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@ReactMethod
|
|
56
|
+
fun getFcmToken(promise: Promise) {
|
|
57
|
+
try {
|
|
58
|
+
val token = Courier.shared.fcmToken
|
|
59
|
+
promise.resolve(token)
|
|
60
|
+
} catch (e: Exception) {
|
|
61
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@ReactMethod
|
|
66
|
+
fun setFcmToken(token: String, promise: Promise) {
|
|
67
|
+
Courier.shared.setFCMToken(
|
|
68
|
+
token,
|
|
69
|
+
onSuccess = {
|
|
70
|
+
promise.resolve(null)
|
|
71
|
+
},
|
|
72
|
+
onFailure = { e ->
|
|
73
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
fun getUserId(promise: Promise) {
|
|
80
|
+
try {
|
|
81
|
+
val userId = Courier.shared.userId
|
|
82
|
+
promise.resolve(userId)
|
|
83
|
+
} catch (e: Exception) {
|
|
84
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@ReactMethod
|
|
89
|
+
fun signOut(promise: Promise) {
|
|
90
|
+
Courier.shared.signOut(
|
|
91
|
+
onSuccess = {
|
|
92
|
+
promise.resolve(null)
|
|
93
|
+
},
|
|
94
|
+
onFailure = { e ->
|
|
95
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@ReactMethod
|
|
101
|
+
fun sendPush(
|
|
102
|
+
authKey: String,
|
|
103
|
+
userId: String,
|
|
104
|
+
title: String,
|
|
105
|
+
body: String,
|
|
106
|
+
providers: ReadableArray,
|
|
107
|
+
isProduction: Boolean,
|
|
108
|
+
promise: Promise
|
|
109
|
+
) {
|
|
110
|
+
Courier.shared.sendPush(
|
|
111
|
+
authKey = authKey,
|
|
112
|
+
userId = userId,
|
|
113
|
+
title = title,
|
|
114
|
+
body = body,
|
|
115
|
+
providers = providers.toCourierProviders(),
|
|
116
|
+
isProduction = isProduction,
|
|
117
|
+
onSuccess = { messageId ->
|
|
118
|
+
promise.resolve(messageId)
|
|
119
|
+
},
|
|
120
|
+
onFailure = { e ->
|
|
121
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
fun requestNotificationPermission(promise: Promise) {
|
|
128
|
+
try {
|
|
129
|
+
reactActivity?.requestNotificationPermission { isGranted ->
|
|
130
|
+
val status = if (isGranted) NotificationPermissionStatus.AUTHORIZED else NotificationPermissionStatus.DENIED
|
|
131
|
+
promise.resolve(status.value)
|
|
132
|
+
}
|
|
133
|
+
} catch (e: Exception) {
|
|
134
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@ReactMethod
|
|
139
|
+
fun getNotificationPermissionStatus(promise: Promise) {
|
|
140
|
+
try {
|
|
141
|
+
reactActivity?.getNotificationPermissionStatus { isGranted ->
|
|
142
|
+
val status = if (isGranted) NotificationPermissionStatus.AUTHORIZED else NotificationPermissionStatus.DENIED
|
|
143
|
+
promise.resolve(status.value)
|
|
144
|
+
}
|
|
145
|
+
} catch (e: Exception) {
|
|
146
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@ReactMethod
|
|
151
|
+
fun registerPushNotificationClickedOnKilledState() {
|
|
152
|
+
reactActivity?.let { activity ->
|
|
153
|
+
checkIntentForPushNotificationClick(activity.intent)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
158
|
+
intent?.trackPushNotificationClick { message ->
|
|
159
|
+
postPushNotificationClicked(message)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
164
|
+
sendEvent(
|
|
165
|
+
reactApplicationContext,
|
|
166
|
+
COURIER_PUSH_NOTIFICATION_CLICKED_EVENT,
|
|
167
|
+
JSONObject(message.pushNotification).toString()
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ReactMethod
|
|
172
|
+
fun setDebugMode(isDebugging: Boolean, promise: Promise) {
|
|
173
|
+
try {
|
|
174
|
+
Courier.shared.isDebugging = isDebugging
|
|
175
|
+
promise.resolve(Courier.shared.isDebugging)
|
|
176
|
+
} catch (e: Exception) {
|
|
177
|
+
promise.reject(COURIER_ERROR_TAG, e)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private fun sendEvent(reactContext: ReactContext, eventName: String, params: String) {
|
|
182
|
+
reactContext
|
|
183
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
184
|
+
.emit(eventName, params)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private fun ReadableArray.toCourierProviders(): List<CourierProvider> {
|
|
188
|
+
val providers: MutableList<CourierProvider> = mutableListOf()
|
|
189
|
+
for (provider in toArrayList()) {
|
|
190
|
+
CourierProvider.values().forEach {
|
|
191
|
+
if (it.value == provider) {
|
|
192
|
+
providers.add(it)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return providers
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CourierReactNativePackage : ReactPackage {
|
|
10
|
+
|
|
11
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
12
|
+
return listOf(CourierReactNativeModule(reactContext))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
16
|
+
return emptyList()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "courier-react-native"
|
|
8
|
+
s.version = package["version"]
|
|
9
|
+
s.summary = package["description"]
|
|
10
|
+
s.homepage = package["homepage"]
|
|
11
|
+
s.license = package["license"]
|
|
12
|
+
s.authors = package["author"]
|
|
13
|
+
|
|
14
|
+
s.platforms = { :ios => "13.0" }
|
|
15
|
+
s.source = { :git => "https://github.com/trycourier/courier-react-native.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
|
+
|
|
19
|
+
s.dependency "React-Core"
|
|
20
|
+
s.dependency 'Courier-iOS', '1.0.20'
|
|
21
|
+
s.swift_version = '5.6'
|
|
22
|
+
|
|
23
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
24
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
25
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
26
|
+
s.pod_target_xcconfig = {
|
|
27
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
28
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
s.dependency "React-Codegen"
|
|
32
|
+
s.dependency "RCT-Folly"
|
|
33
|
+
s.dependency "RCTRequired"
|
|
34
|
+
s.dependency "RCTTypeSafety"
|
|
35
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(CourierReactNative, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(signIn:(NSString*)userId
|
|
6
|
+
accessToken:(NSString*)accessToken
|
|
7
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
8
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
|
|
10
|
+
RCT_EXTERN_METHOD(signOut: (RCTPromiseResolveBlock)resolve
|
|
11
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN_METHOD(getUserId: (RCTPromiseResolveBlock)resolve
|
|
14
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
15
|
+
|
|
16
|
+
RCT_EXTERN_METHOD(getFcmToken: (RCTPromiseResolveBlock)resolve
|
|
17
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
18
|
+
|
|
19
|
+
RCT_EXTERN_METHOD(setFcmToken:(NSString*)token
|
|
20
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
21
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
22
|
+
|
|
23
|
+
RCT_EXTERN_METHOD(getApnsToken: (RCTPromiseResolveBlock)resolve
|
|
24
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
25
|
+
|
|
26
|
+
RCT_EXTERN_METHOD(getNotificationPermissionStatus: (RCTPromiseResolveBlock)resolve
|
|
27
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
28
|
+
|
|
29
|
+
RCT_EXTERN_METHOD(requestNotificationPermission: (RCTPromiseResolveBlock)resolve
|
|
30
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
31
|
+
|
|
32
|
+
RCT_EXTERN_METHOD(sendPush: (NSString*)authKey
|
|
33
|
+
withUserId:(NSString*)userId
|
|
34
|
+
withTitle:(NSString*)title
|
|
35
|
+
withBody:(NSString*)body
|
|
36
|
+
withProviders:(NSArray*)providers
|
|
37
|
+
withIsProduction:(BOOL)isProduction
|
|
38
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
39
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
40
|
+
|
|
41
|
+
RCT_EXTERN_METHOD(registerPushNotificationClickedOnKilledState)
|
|
42
|
+
RCT_EXTERN_METHOD(iOSForegroundPresentationOptions: (NSDictionary*) params)
|
|
43
|
+
RCT_EXTERN_METHOD(setDebugMode: (BOOL)isDebugging
|
|
44
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
45
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
+ (BOOL)requiresMainQueueSetup
|
|
49
|
+
{
|
|
50
|
+
return YES;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@end
|