Collect SDK information from an app install
The Acoustic Campaign SDK provides support for you to verify if the SDK is installed in your app. You can also find the SDK version and retrieve registration details, such as userID
, channelID,
and appKey
.
Detect SDK installation
When using iOS, you can detect if the SDK is installed by employing the following code:
// Detecting if Acoustic SDK is installed
if(NSClassFromString(@"MCESdk"))
{
NSLog(@"Acoustic SDK Installed.");
}
else
{
NSLog(@"Acoustic SDK Not Installed.");
}
Check SDK version
Use the following code to acquire the version of the SDK:
NSString* versionNum = [MCESdk sharedInstance].sdkVersion;
NSLog(@"Acoustic SDK version %@", versionNum);
Retrieve SDK registration details for the device
The registration details include important values that are related to the SDK registration for each unique app install.
Note:
The registration detail properties are not available until the device is registered. Registration happens within seconds of first launching your mobile app.
You can get the MCE registration details in the AppDelegate
class or use the observer pattern to get the registration details and send them to your server.
Use the following methods to get MCE registration details in the App Delegate
class:
-(void) aquireIdentification: (NSNotification*)note
{
NSString * userId = MCERegistrationDetails.sharedInstance.userId;
NSString * channelId = MCERegistrationDetails.sharedInstance.channelId;
NSString * appKey = MCERegistrationDetails.sharedInstance.userId;
// logging for immediate validation upon install;
remove for production NSLog(@"muid::: %@", userId);
NSLog(@"channel id::: %@", channelId);
NSLog(@"appkey::: %@", appKey);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aquireIdentification:) name: @"MCERegisteredNotification" object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aquireIdentification:) name: @"MCERegistrationChangedNotification" object: nil];
}
Note:
NSNotification is required to know when the device registers with the MCE servers.
Enable file sharing to save the SDK registration details to iTunes. When file sharing is enabled, the following details are saved in the mce-details.txt
file:
- user ID,
- channel ID,
- environment information
- configuration information such as log level, app key, base URL, and session timeout
This information is helpful when you try to debug problems.
To enable file sharing, set theUIFileSharingEnabled
flag toYES
in info.plist.
Detect SDK installation
To detect if the SDK is installed, use the following code:
// Detecting if Acoustic SDK is installed
try {
Class.forName("co.acoustic.mobile.push.sdk.api.MceSdk");
System.out.println("Acoustic SDK installed");
} catch (ClassNotFoundException e) {
System.out.println("Acoustic SDK not installed");
}
Check SDK version
Use the following code to acquire the version of the SDK:
String versionNum = MceSdk.getSdkVerNumber();
System.out.println("Acoustic SDK Version: " + versionNum);
Retrieve SDK registration details
The registration details include important values that are related to the SDK registration for each unique app install.
Note:
The registration detail properties are not available until the device is registered. Registration happens within seconds of first launching your mobile app.
The Android SDK registration includes the following properties:
- channel ID
- user ID
- Is push registered - a flag that indicates whether the device is registered with FCM (true if registered, false if not registered).
- Push token - the registration ID received from FCM after registration. This value is null if registration has not been performed yet.
You can get the registration details using the following methods:
- Grab the details properties in Java.
The following example shows you how to grab the details properties in Java:RegistrationDetails registrationDetails = MceSdk.getRegistrationClient().getRegistrationDetails(getApplicationContext()); String channelId= registrationDetails.getChannelId(); String userId=registrationDetails.getUserId(); boolean isPushRegistered= registrationDetails.isPushRegistered(); String pushToken= registrationDetails.getPushToken(); String appKey = MceSdk.getRegistrationClient().getAppKey(getApplicationContext()); - Implement the MceBroadcastReceiver class to get the registration details and send them to your server
The MceBroadcastReceiver class retrieves the user ID and channel ID in the onSdkRegistered method by using the MceSdk.getRegistrationDetails().getUserId() and MceSdk.getRegistrationDetails().getChannelId() methods. - Obtain MCE registration details by using MceNotificationActionRegistry
MceNotificationActionRegistry is for registering custom SDK notification actions. - Implement onDeliveyChannelRegistered method
If you want to obtain the push token, you must implement the onDeliveyChannelRegistered method and use the 'MceSdk.getRegistrationDetails().getPushToken()' method.
To get the registration details when using React Native, you must add the listener methods below and then retrieve the registration details. Once retrieved, you can then use these values or send them to your service and associate the values with a named user account.
import {RNAcousticMobilePush} from 'NativeModules';
import {NativeEventEmitter} from 'react-native';
const emitter = new NativeEventEmitter(RNAcousticMobilePush);
emitter.addListener('Registered', ()=>{ updateRegistration(); });
emitter.addListener('RegistrationChanged', ()=>{ updateRegistration(); });
function updateRegistration() {
RNAcousticMobilePush.registrationDetails().then((registrationDetails) => {
const registration = {userId: registrationDetails.userId, channelId: registrationDetails.channelId, appKey: RNAcousticMobilePush.appKey};
// Send registration details to server here
});
}
When using Cordova, you can get the registration details using the following methods:
- Subscribe to delegate methods by specifying a method to be called or a block of code to be executed. You can subscribe to changes in registration by using the following code:
MCEPlugin.getRegistrationDetails(function(details) { if (typeof details.userId == "undefined" || typeof details.channelId == "undefined") { // Not yet registered, no user/channel } console.log("UserId is " + details.userId); console.log("ChannelId is " + details.channelId); }); MCEPlugin.getAppKey(function(appKey) { console.log("AppKey is " + appKey); }
- If you want to obtain the registration details and send it to your server, do it in the MCEPlugin.setRegistrationCallback(function(details) mechanism.
You can get the registration details using the following methods:
- Add the necessary imports.
import 'package:flutter/material.dart';
import 'package:flutter_acoustic_mobile_push/flutter_acoustic_sdk_push.dart';
- Create and add the following variables and function to get the registration details.
// Create the following variables
var _userId = "";
var _channelId = "";
var _appKey = "";
// Add the following function
Future<void> getDataFromSDK() async {
var value = RegisiterValue();
value.getRegisterValue();
value.userId.subscribe((args) {
var data = args!.changedValue;
setState(() {
_userId = data;
});
});
value.channelId.subscribe((args) {
var data = args!.changedValue;
setState(() {
_channelId = data;
});
});
value.appKey.subscribe((args) {
var data = args!.changedValue;
setState(() {
_appKey = data;
});
});
}
- Whenever you need registration details call the
getDataFromSDK
function.
Updated 9 months ago