Skip to content

Commit

Permalink
Pull request #131: Sloncarevic/MM-6838 remove geo support
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-react-native-plugin from sloncarevic/MM-6838-remove-geo-support to master

Squashed commit of the following:

commit 8ca263e2c57e3e09e6c1b90a39d79715030049e6
Author: sloncarevic <[email protected]>
Date:   Wed Oct 9 14:12:16 2024 +0200

    remove geo

commit 71c418d2685c73d73f10659ab6b5140fc4b77e93
Merge: d860246 45eaa40
Author: sloncarevic <[email protected]>
Date:   Wed Oct 9 11:33:20 2024 +0200

    Merge branch 'master' into sloncarevic/MM-6838-remove-geo-support

    # Conflicts:
    #	infobip-mobile-messaging-react-native-plugin.podspec

commit d860246519a8ae39cf88f2943dea58b5c2115b81
Author: sloncarevic <[email protected]>
Date:   Wed Oct 9 10:56:39 2024 +0200

    remove geo
  • Loading branch information
Saša Lončarević authored and Saša Lončarević committed Oct 15, 2024
1 parent 45eaa40 commit 84bedad
Show file tree
Hide file tree
Showing 13 changed files with 1 addition and 299 deletions.
99 changes: 1 addition & 98 deletions Example/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, {Component} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {Platform} from 'react-native';

//Screens
import HomeScreen from './screens/HomeScreen';
Expand All @@ -17,28 +15,12 @@ import {mobileMessaging} from 'infobip-mobile-messaging-react-native-plugin';
import {webRTCUI} from 'infobip-mobile-messaging-react-native-plugin';
import Colors from './constants/Colors';
import MyMessageStorage from './constants/MyMessageStorage';
import NativeDialogManagerAndroid from 'react-native/Libraries/NativeModules/specs/NativeDialogManagerAndroid';
import {Rationale} from 'react-native';

const Stack = createNativeStackNavigator();

const myMessageStorage = MyMessageStorage;

export default class App extends Component {
androidGeoProminentDisclosureAcceptedKey: string =
'androidGeoProminentDisclosureAcceptedKey';

isAndroidGeoProminentDisclosureAccepted(): Promise<Boolean> {
return AsyncStorage.getItem(
this.androidGeoProminentDisclosureAcceptedKey,
).then(value => {
if (value === null) {
return Promise.resolve(false);
}
return Promise.resolve(JSON.parse(value));
});
}

configuration = {
applicationCode: 'Your mobile push profile application code',
webRTCUI: {
Expand All @@ -51,7 +33,6 @@ export default class App extends Component {
messageStorage: myMessageStorage,
inAppChatEnabled: true,
fullFeaturedInAppsEnabled: true,
geofencingEnabled: false,
loggingEnabled: true,
};

Expand All @@ -62,68 +43,7 @@ export default class App extends Component {
};
this.subscriptions = [];

if (Platform.OS === 'ios' || !this.configuration.geofencingEnabled) {
this.initMobileMessaging();
return;
}

/* Starting Mobile Messaging SDK for android in case geofencingEnabled: true */

// 1. Setup geo disclosure dialog
// Per Google requirements - "If your app accesses location in the background, you must provide an in-app disclosure of your data access, collection, use, and sharing."
let androidGeoDisclosureDialog = {
message:
'This application collects location data to be able to trigger notification about entering geo region even when the app is closed or not in use.',
buttonPositive: 'accept',
buttonNeutral: 'decline',
};

// 2. Setup rationale which will be displayed if it's required for asking geofencing permissions.
//It'll be displayed before showing settings screen with location permissions.
let androidGeoPermissionsRationaleOptions = {
title: 'Update location settings',
message:
'Allow application to access your location all the time to let it trigger geo notifications even when app is closed or not in use',
buttonNegative: 'cancel',
buttonPositive: 'settings',
};

// 3. Check was geo disclosure dialog accepted or not
this.isAndroidGeoProminentDisclosureAccepted().then(accepted => {
if (accepted === true) {
this.initMobileMessagingWithRequestingGeoPermissions(
androidGeoPermissionsRationaleOptions,
);
return;
}

// 4. Show geo disclosure dialog if it's not accepted
// Example application displays this dialog until user accepts it.
NativeDialogManagerAndroid.showAlert(
androidGeoDisclosureDialog,
() => {},
(action, buttonKey) => {
console.log('Button key: ' + buttonKey);
if (buttonKey === -1) {
//accepted
AsyncStorage.setItem(
this.androidGeoProminentDisclosureAcceptedKey,
JSON.stringify(true),
);

// 4.1 Request geofencing permissions and initialize Mobile Messaging
this.initMobileMessagingWithRequestingGeoPermissions(
androidGeoPermissionsRationaleOptions,
);
} else {
// 4.2 initialize Mobile Messaging
// Initialize will be called with geofencingEnabled: true, user can give permissions later.
// Geofencing won't work until permissions are granted.
this.initMobileMessaging();
}
},
);
});
this.initMobileMessaging();
}

componentDidMount() {
Expand All @@ -148,23 +68,6 @@ export default class App extends Component {
this.updateLogInfo('Event: ' + JSON.stringify(value));
};

initMobileMessagingWithRequestingGeoPermissions(
androidGeoPermissionsRationale: Rationale,
) {
//Request geofencing permissions using mobileMessaging method, you can create your own implementation if provided isn't suite.
mobileMessaging
.requestAndroidLocationPermissions(androidGeoPermissionsRationale)
.then(granted => {
if (!granted) {
console.log('Required Geofencing permissions are not granted.');
}

// Initialize will be called with geofencingEnabled: true, user can give permissions later.
// Geofencing won't work until permissions are granted.
this.initMobileMessaging();
});
}

initMobileMessaging() {
mobileMessaging.init(
this.configuration,
Expand Down
1 change: 0 additions & 1 deletion Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ buildscript {
compileSdkVersion = 33
targetSdkVersion = 33
withCryptorMigration = false
withGeofencingModule = false
withWebRTCUI = true
overrideKotlinVersion = "1.8.10"

Expand Down
6 changes: 0 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def overrideGmsVersion = getRootProjectProperty('overrideGmsVersion', '')
def overrideFirebaseVersion = getRootProjectProperty('overrideFirebaseVersion', '')
def overrideKotlinVersion = getRootProjectProperty('overrideKotlinVersion', '')
def withCryptorMigration = getRootProjectProperty('withCryptorMigration', false)
def withGeofencingModule = getRootProjectProperty('withGeofencingModule', false)
def withWebRTCUI = getRootProjectProperty('withWebRTCUI', false)

apply plugin: 'com.android.library'
Expand Down Expand Up @@ -131,9 +130,4 @@ dependencies {
implementation "com.infobip:infobip-mobile-messaging-android-cryptor-migration:$mmVersion@aar"
}

if (withGeofencingModule.toBoolean()) {
implementation ("com.infobip:infobip-mobile-messaging-android-geo-sdk:$mmVersion@aar"){
transitive = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class WebRTCUI {

AndroidConfiguration android;
String applicationCode;
boolean geofencingEnabled;
boolean inAppChatEnabled;
boolean fullFeaturedInAppsEnabled;
Map<String, ?> messageStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public void removeListeners(Integer count) {
private static final String EVENT_PERSONALIZED = "personalized";
private static final String EVENT_DEPERSONALIZED = "depersonalized";

private static final String EVENT_GEOFENCE_ENTERED = "geofenceEntered";
private static final String EVENT_NOTIFICATION_TAPPED = "notificationTapped";
private static final String EVENT_NOTIFICATION_ACTION_TAPPED = "actionTapped";
private static final String EVENT_MESSAGE_RECEIVED = "messageReceived";
Expand All @@ -173,9 +172,6 @@ public void removeListeners(Integer count) {
private static final String EVENT_INAPPCHAT_AVAILABILITY_UPDATED = "inAppChat.availabilityUpdated";
//endregion

//Geo dependency is opt-out by default. Extracted from GeoEvent.GEOFENCE_AREA_ENTERED module 'infobip-mobile-messaging-android-geo-sdk'
private static final String GEO_EVENT_GEOFENCE_AREA_ENTERED_KEY = "org.infobip.mobile.messaging.geo.GEOFENCE_AREA_ENTERED";


//region MessageStorageBroadcastReceiver
private static final Map<String, String> messageStorageEventMap = new HashMap<String, String>() {{
Expand Down Expand Up @@ -296,7 +292,6 @@ private ReactContext getReactContext(Context context) {
put(Event.USER_UPDATED.getKey(), EVENT_USER_UPDATED);
put(Event.PERSONALIZED.getKey(), EVENT_PERSONALIZED);
put(Event.DEPERSONALIZED.getKey(), EVENT_DEPERSONALIZED);
put(GEO_EVENT_GEOFENCE_AREA_ENTERED_KEY, EVENT_GEOFENCE_ENTERED);
put(InAppChatEvent.CHAT_VIEW_CHANGED.getKey(), EVENT_INAPPCHAT_VIEW_STATE_CHANGED);
put(InAppChatEvent.CHAT_CONFIGURATION_SYNCED.getKey(), EVENT_INAPPCHAT_CONFIGURATION_SYNCED);
put(InAppChatEvent.LIVECHAT_REGISTRATION_ID_UPDATED.getKey(), EVENT_INAPPCHAT_LIVECHAT_REGISTRATION_ID_UPDATED);
Expand All @@ -313,13 +308,6 @@ public void onReceive(Context context, Intent intent) {
return;
}

if (GEO_EVENT_GEOFENCE_AREA_ENTERED_KEY.equals(intent.getAction())) {
for (JSONObject geo : MessageJson.geosFromBundle(intent.getExtras())) {
ReactNativeEvent.send(event, reactContext, geo);
}
return;
}

if (Event.INSTALLATION_UPDATED.getKey().equals(intent.getAction())) {
JSONObject updatedInstallation = InstallationJson.toJSON(Installation.createFrom(intent.getExtras()));
ReactNativeEvent.send(event, reactContext, updatedInstallation);
Expand Down Expand Up @@ -471,19 +459,6 @@ public void init(ReadableMap args, final Callback successCallback, final Callbac
@SuppressLint("MissingPermission")
@Override
public void onSuccess() {
if (configuration.geofencingEnabled) {
try {
Class<?> cls = Class.forName("org.infobip.mobile.messaging.geo.MobileGeo");
Method newInstance_method = cls.getDeclaredMethod("getInstance", Context.class);
Method activateGeofencing_method = cls.getDeclaredMethod("activateGeofencing");
Object geoInstance = newInstance_method.invoke(cls, context);
activateGeofencing_method.invoke(geoInstance);
} catch (Exception e) {
Log.d(Utils.TAG, "Geofencing is not enabled.");
e.printStackTrace();
}
}

NotificationCategory categories[] = notificationCategoriesFromConfiguration(configuration.notificationCategories);
if (categories.length > 0) {
MobileInteractive.getInstance(context).setNotificationCategories(categories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static JSONObject toJSON(Message message) {
.putOpt("contentUrl", message.getContentUrl())
.putOpt("seen", message.getSeenTimestamp() != 0)
.putOpt("seenDate", message.getSeenTimestamp())
.putOpt("geo", hasGeo(message))
.putOpt("chat", message.isChatMessage())
.putOpt("browserUrl", message.getBrowserUrl())
.putOpt("webViewUrl", message.getWebViewUrl())
Expand All @@ -68,19 +67,6 @@ public static JSONObject toJSON(Message message) {
}
}

private static boolean hasGeo(Message message) {
if (message == null || message.getInternalData() == null) {
return false;
}

try {
JSONObject geo = new JSONObject(message.getInternalData());
return geo.getJSONArray("geo") != null && geo.getJSONArray("geo").length() > 0;
} catch (JSONException e) {
return false;
}
}

/**
* Creates array of json objects from list of messages
*
Expand Down Expand Up @@ -135,26 +121,6 @@ private static Message fromJSON(JSONObject json) {
return message;
}

/**
* Geo mapper
*
* @param bundle where to read geo objects from
* @return list of json objects representing geo objects
*/
@NonNull
public static List<JSONObject> geosFromBundle(Bundle bundle) {
try {
Class<?> cls = Class.forName("org.infobip.mobile.messaging.geo.mapper.GeoBundleMapper");
Method geosFromBundle_method = cls.getDeclaredMethod("geosFromBundle", Bundle.class);
List<JSONObject> geos = (List<JSONObject>) geosFromBundle_method.invoke(cls, bundle);
return geos;
} catch (Exception e) {
Log.w(Utils.TAG, "Cannot convert geo to JSON: " + e.getMessage());
Log.d(Utils.TAG, Log.getStackTraceString(e));
}
return new ArrayList<JSONObject>();
}

@NonNull
public static List<Message> resolveMessages(JSONArray args) throws JSONException {
if (args == null || args.length() < 1 || args.getString(0) == null) {
Expand Down
1 change: 0 additions & 1 deletion infobip-mobile-messaging-react-native-plugin.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Pod::Spec.new do |s|

s.dependency "React-Core"
s.dependency "MobileMessaging/Core", "12.13.2"
s.dependency "MobileMessaging/Geofencing", "12.13.2"
s.dependency "MobileMessaging/InAppChat", "12.13.2"
s.dependency "MobileMessaging/Inbox", "12.13.2"
if defined?($WebRTCUIEnabled)
Expand Down
5 changes: 0 additions & 5 deletions ios/MobileMessagingPlugin/RNMobileMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ReactNativeMobileMessaging: RCTEventEmitter {
EventName.userUpdated,
EventName.personalized,
EventName.depersonalized,
EventName.geofenceEntered,
EventName.actionTapped,
EventName.notificationTapped,
EventName.messageReceived,
Expand Down Expand Up @@ -123,10 +122,6 @@ class ReactNativeMobileMessaging: RCTEventEmitter {

var mobileMessaging = MobileMessaging.withApplicationCode(configuration.appCode, notificationType: configuration.notificationType)

if configuration.geofencingEnabled {
mobileMessaging = mobileMessaging?.withGeofencingService()
}

if let storageAdapter = messageStorageAdapter, configuration.messageStorageEnabled {
mobileMessaging = mobileMessaging?.withMessageStorage(storageAdapter)
} else if configuration.defaultMessageStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class RNMobileMessagingConfiguration {
static let carrierInfoSendingDisabled = "carrierInfoSendingDisabled"
static let systemInfoSendingDisabled = "systemInfoSendingDisabled"
static let applicationCodePersistingDisabled = "applicationCodePersistingDisabled"
static let geofencingEnabled = "geofencingEnabled"
static let applicationCode = "applicationCode"
static let webRTCUI = "webRTCUI"
static let configurationId = "configurationId"
Expand All @@ -34,7 +33,6 @@ class RNMobileMessagingConfiguration {

let appCode: String
let webRTCUI: [String: AnyObject]?
let geofencingEnabled: Bool
let messageStorageEnabled: Bool
let defaultMessageStorage: Bool
let notificationType: MMUserNotificationType
Expand All @@ -55,7 +53,6 @@ class RNMobileMessagingConfiguration {

self.appCode = appCode
self.webRTCUI = rawConfig[RNMobileMessagingConfiguration.Keys.webRTCUI] as? [String: AnyObject]
self.geofencingEnabled = rawConfig[RNMobileMessagingConfiguration.Keys.geofencingEnabled].unwrap(orDefault: false)
self.logging = ios[RNMobileMessagingConfiguration.Keys.logging].unwrap(orDefault: false)
self.defaultMessageStorage = rawConfig[RNMobileMessagingConfiguration.Keys.defaultMessageStorage].unwrap(orDefault: false)
self.messageStorageEnabled = rawConfig[RNMobileMessagingConfiguration.Keys.messageStorage] != nil ? true : false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class RNMobileMessagingEventsManager {
EventName.messageReceived: MMNotificationMessageReceived,
EventName.tokenReceived: MMNotificationDeviceTokenReceived,
EventName.registrationUpdated: MMNotificationRegistrationUpdated,
EventName.geofenceEntered: MMNotificationGeographicalRegionDidEnter,
EventName.notificationTapped: MMNotificationMessageTapped,
EventName.actionTapped: MMNotificationActionTapped,
EventName.depersonalized: MMNotificationDepersonalized,
Expand Down Expand Up @@ -85,11 +84,6 @@ class RNMobileMessagingEventsManager {
if let internalId = notification.userInfo?[MMNotificationKeyRegistrationInternalId] as? String {
notificationResult = internalId
}
case MMNotificationGeographicalRegionDidEnter:
eventName = EventName.geofenceEntered
if let region = notification.userInfo?[MMNotificationKeyGeographicalRegion] as? MMRegion {
notificationResult = region.dictionary()
}
case MMNotificationMessageTapped:
eventName = EventName.notificationTapped
if let message = notification.userInfo?[MMNotificationKeyMessage] as? MM_MTMessage {
Expand Down
Loading

0 comments on commit 84bedad

Please sign in to comment.