Manually add and configure frameworks
Overview
The Acoustic Campaign Native mobile SDKs provide automatic and manual methods to implement the SDK in your applications.
You can add the Acoustic Mobile React Native SDK to your application using the automatic method described here: Add the React Native plug-in to your app.
The following instructions provide an alternative method to manually implement the SDK in your project if your application doesn't meet the requirements for automatic implementation.
Before you begin
If needed, create a sample project.
npx react-native init ProjectName --version 0.68.2
Remove previous configuration
If you have the Acoustic React Native mobile push SDK configured in your application, you must remove that configuration before you proceed.
-
Remove the following dependencies from the package.json file in your application:
"react-native-acoustic-mobile-push": "file:../plugins/react-native-acoustic-mobile-push", "react-native-ios-notification-service": "file:../plugins/react-native-ios-notification-service", -
Delete the react-native-acoustic-mobile-push and react-native-ios-notification-service folders and all their content.
-
Run
pod deintegrate
on your iOS folder. -
Run
yarn install
on your project root folder. -
Run
pod install
on your iOS folder.
Configure project
Add capabilities
In your main target, add the following capabilities:
- push notification capability
- App Groups capability and ensure that your selected app group is equal to
group.{your Bundle Identifier}
.
Add frameworks
- Add the AcousticMobilePush.xcframework and AcousticMobilePushNotification.xcframework frameworks on the main target in the Frameworks, Libraries, and Embedded Content section.
- Ensure that your main target Build Phases has only one Framework (
AcousticMobilePush.xcframework
) added on the Link Binary with Libraries section. - Also, ensure that both frameworks are present in the Embed Frameworks section.
Update/Add the required files
- Change your main.m from your project with the following:#import <UIKit/UIKit.h> int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, @"MCEAppDelegate"); } }
- Add the following four communication files from the plugins folder to your project at the same level as the main.m file.
- RNAcousticMobilePush.h
- RNAcousticMobilePush.m
- RNAcousticMobilePushActionHandler.h
- RNAcousticMobilePushActionHandler.m
- Add the MCEConfig.json file and update it with the required information.
Create Notification Service Extension
-
To add a new Notification Extension Target, go to Xcode > File > New > Target.
-
Select Notification Extension Target.
-
Name it NotificationService. Make sure you add this to your main project and application.
-
Select Objective C as the language and click Finish.
-
Activate the
NotificationService
scheme when prompted by Xcode. Xcode creates a new folder called NotificationService with the files in it. -
Make sure that your Deployment Info Version equals your main target.
-
In the NotificationService target, add the App Groups capability and ensure that your selected app group equals your main target.
-
Update the file from the NotificationService folder:
#import <UserNotifications/UserNotifications.h> #import <AcousticMobilePushNotification/AcousticMobilePushNotification.h> @interface NotificationService : MCENotificationService @end#import "NotificationService.h" @implementation NotificationService @end
Warning:
After running the project, sometimes Xcode adds the AcousticMobilePushNotification.xcframework to the Link Binary With Libraries section (Build phases); make sure to delete it from there.
Note:
Check that the MCEConfig.json file has both targets selected under Target Membership.
Add the request for push permission
Add the following:
Note:
The code is added to the app.tsx file here as an example.
-
Import NativeModules from react-native:
import { NativeModules,} from 'react-native'; -
Add the following constant after importing:
const { RNAcousticMobilePush } = NativeModules; -
Use the following
RNAcousticMobilePush
function:React.useEffect(() => { RNAcousticMobilePush.requestPushPermission(); }, [])componentDidMount() { RNAcousticMobilePush.requestPushPermission(); }
Remove previous configuration
If you have the Acoustic React Native mobile push SDK configured in your application, you must remove that configuration before you proceed.
- Remove the
react-native-acoustic-mobile-push
dependency in the package.json file in your application."react-native-acoustic-mobile-push": "file:../plugins/react-native-acoustic-mobile-push", - Delete the ../plugins/react-native-acoustic-mobile-push folder and all its content.
- Run
yarn install
on your project root folder.
Configure project
Add frameworks
From the Acoustic React Native GitHub repo, add the following files from the plugins/react-native-acoustic-mobile-push/android/libs folder to your app project's android/app/libs folder.
- acoustic-mobile-push-android-sdk-3.8.7.aar
- acoustic-mobile-push-android-sdk-plugin-inapp-3.8.7.aar
- acoustic-mobile-push-android-sdk-plugin-inbox-3.8.7.aar
Update/Add the required files
-
Add the following four communication files from the plugins folder to your app's required path src/main/java/co/acoustic/mobile/push.
- RNAcousticMobilePushActionHandler.java
- RNAcousticMobilePushBroadcastReceiver.java
- RNAcousticMobilePushModule.java
- RNAcousticMobilePushPackage.java
-
Add the MCEConfig.json file and update it with the required information.
-
Add the google-services.json file and update it with the required information.
-
Update the project build.gradle file to include the google-services dependency:
classpath("com.google.gms:google-services:4.3.3") -
Update the app build.gradle file as follows:
- Add
.aar
dependency support:implementation fileTree(dir: "libs", include: ["*.jar","*.aar"]) - Add
google-play-services
andfirebase
dependencies:apply plugin: "com.google.gms.google-services" implementation 'com.google.android.gms:play-services-base:16.0.1' implementation 'com.google.android.gms:play-services-location:16.0.0' implementation 'com.google.firebase:firebase-messaging:22.0.0'
- Add
-
Update the MainApplication.java file to include
RNAcousticMobilePushPackage
manually using thegetPackages()
method.import co.acoustic.mobile.push.RNAcousticMobilePushPackage;
packages.add(new RNAcousticMobilePushPackage());
-
Update the AndroidManifest.xml file to include the following:
<manifest ... xmlns:tools="http://schemas.android.com/tools" ... > <application ... tools:replace="android:name" ... > <activity ...> ... </activity> <receiver android:exported="true" android:name="co.acoustic.mobile.push.RNAcousticMobilePushBroadcastReceiver"> <intent-filter> <action android:name="co.acoustic.mobile.push.sdk.NOTIFIER"/> </intent-filter> </receiver> <receiver android:name="co.acoustic.mobile.push.sdk.notification.NotifActionReceiver"/> <provider android:name="co.acoustic.mobile.push.sdk.db.Provider" android:authorities="${applicationId}.MCE_PROVIDER" android:exported="false"/> <service android:name="co.acoustic.mobile.push.sdk.session.SessionTrackingIntentService"/> <service android:name="co.acoustic.mobile.push.sdk.events.EventsAlarmListener"/> <service android:name="co.acoustic.mobile.push.sdk.registration.PhoneHomeIntentService"/> <service android:name="co.acoustic.mobile.push.sdk.registration.RegistrationIntentService"/> <service android:name="co.acoustic.mobile.push.sdk.attributes.AttributesQueueConsumer"/> <service android:name="co.acoustic.mobile.push.sdk.job.MceJobService" android:permission="android.permission.BIND_JOB_SERVICE"/> <service android:name="co.acoustic.mobile.push.sdk.messaging.fcm.FcmMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> </application> </manifest>
Add the request for push permission
Add the following:
Note:
The code is added to the app.tsx file here as an example.
-
Import NativeModules from react-native:
import { NativeModules,} from 'react-native'; -
Add the following constant after importing:
const { RNAcousticMobilePush } = NativeModules; -
Use the following
RNAcousticMobilePush
function:React.useEffect(() => { RNAcousticMobilePush.requestPushPermission(); }, [])componentDidMount() { RNAcousticMobilePush.requestPushPermission(); }
Run the app
- Run
yarn install
andyarn android
on your project root folder. - Send a push notification once the app runs on your selected device to verify SDK is working.
Updated 10 months ago