Skip to content

Commit 3b2ccbb

Browse files
committed
Added in test cases for messagingPlatform
1 parent b6bad86 commit 3b2ccbb

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

iterableapi/src/androidTest/java/com/iterable/iterableapi/IterablePushRegistrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void testGetGCMToken() throws Exception {
3838
IterablePushRegistration registration = new IterablePushRegistration();
3939
IterablePushRegistration.PushRegistrationObject registrationObject = registration.getDeviceToken(senderID, IterableConstants.MESSAGING_PLATFORM_GOOGLE, "test_application_GCM", false);
4040
assertNotNull(registrationObject.token);
41+
assertEquals(IterableConstants.MESSAGING_PLATFORM_GOOGLE, registrationObject.messagingPlatform);
4142

4243
SharedPreferences sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
4344
String pushIdPref = sharedPref.getString(IterableConstants.PUSH_APP_ID, null);
@@ -60,12 +61,14 @@ public void testGetFCMToken() throws Exception {
6061
sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
6162
pushIdPref = sharedPref.getString(IterableConstants.PUSH_APP_ID, null);
6263
assertNotNull(pushIdPref);
64+
assertEquals(IterableConstants.MESSAGING_PLATFORM_FIREBASE, registrationObject.messagingPlatform);
6365

6466
} else {
6567
//GCM registration
6668
sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
6769
pushIdPref = sharedPref.getString(IterableConstants.PUSH_APP_ID, null);
6870
assertNull(pushIdPref);
71+
assertEquals(IterableConstants.MESSAGING_PLATFORM_GOOGLE, registrationObject.messagingPlatform);
6972
}
7073
}
7174
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ private void tryTrackNotifOpen(Intent calledIntent) {
726726
* @param pushServicePlatform
727727
* @param dataFields
728728
*/
729-
private void registerDeviceToken(String applicationName, String token, String pushServicePlatform, JSONObject dataFields) {
729+
public void registerDeviceToken(String applicationName, String token, String pushServicePlatform, JSONObject dataFields) {
730730
String platform = IterableConstants.MESSAGING_PLATFORM_GOOGLE;
731731

732732
JSONObject requestJSON = new JSONObject();

iterableapi/src/main/java/com/iterable/iterableapi/IterablePushRegistration.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import com.google.android.gms.iid.InstanceID;
99
import com.google.firebase.iid.FirebaseInstanceId;
1010

11+
import org.json.JSONException;
12+
import org.json.JSONObject;
13+
1114
import java.io.IOException;
1215

1316
/**
@@ -26,20 +29,26 @@ class IterablePushRegistration extends AsyncTask<IterablePushRegistrationData, V
2629
* @return registration token
2730
*/
2831
protected String doInBackground(IterablePushRegistrationData... params) {
29-
PushRegistrationObject PushRegistrationObject = null;
32+
PushRegistrationObject pushRegistrationObject = null;
3033
iterablePushRegistrationData = params[0];
3134
if (iterablePushRegistrationData.iterableAppId != null) {
3235
if (iterablePushRegistrationData.pushRegistrationAction == IterablePushRegistrationData.PushRegistrationAction.ENABLE) {
33-
PushRegistrationObject = getDeviceToken(iterablePushRegistrationData.projectNumber, iterablePushRegistrationData.messagingPlatform, iterablePushRegistrationData.iterableAppId, true);
34-
IterableApi.sharedInstance.registerDeviceToken(iterablePushRegistrationData.iterableAppId, PushRegistrationObject.token, iterablePushRegistrationData.messagingPlatform);
36+
pushRegistrationObject = getDeviceToken(iterablePushRegistrationData.projectNumber, iterablePushRegistrationData.messagingPlatform, iterablePushRegistrationData.iterableAppId, true);
37+
JSONObject data = new JSONObject();
38+
try {
39+
data.put("TokenPlatformType", pushRegistrationObject.messagingPlatform);
40+
} catch (JSONException e) {
41+
IterableLogger.e(TAG, e.toString());
42+
}
43+
IterableApi.sharedInstance.registerDeviceToken(iterablePushRegistrationData.iterableAppId, pushRegistrationObject.token, iterablePushRegistrationData.messagingPlatform, data);
3544
} else if (iterablePushRegistrationData.pushRegistrationAction == IterablePushRegistrationData.PushRegistrationAction.DISABLE) {
36-
PushRegistrationObject = getDeviceToken(iterablePushRegistrationData.projectNumber, iterablePushRegistrationData.messagingPlatform, iterablePushRegistrationData.iterableAppId, false);
37-
IterableApi.sharedInstance.disablePush(PushRegistrationObject.token);
45+
pushRegistrationObject = getDeviceToken(iterablePushRegistrationData.projectNumber, iterablePushRegistrationData.messagingPlatform, iterablePushRegistrationData.iterableAppId, false);
46+
IterableApi.sharedInstance.disablePush(pushRegistrationObject.token);
3847
}
3948
} else {
4049
IterableLogger.e("IterablePush", "The IterableAppId has not been added");
4150
}
42-
return PushRegistrationObject.token;
51+
return pushRegistrationObject.token;
4352
}
4453

4554
/**

0 commit comments

Comments
 (0)