Skip to content

Commit 92842b6

Browse files
committed
Updated callback scenarios to return null within the success callback
* In some wrapper SDKs await statements will hang no callback is sent back * These scenarios include unique outcome for ATTRIBUTED sessions with notifications, UNATTRIBUTED sessions, and Failures * Updated Unity Proxy to have public outcome methods exposed
1 parent fd4b902 commit 92842b6

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

OneSignalSDK/app/src/main/java/com/onesignal/MainActivity.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.os.Bundle;
3535
import android.os.Handler;
3636
import android.os.Looper;
37+
import android.support.annotation.Nullable;
3738
import android.util.Log;
3839
import android.view.Menu;
3940
import android.view.MenuItem;
@@ -330,17 +331,19 @@ public void onFailure(OneSignal.EmailUpdateError error) {
330331
public void onSendOutcomeClicked(View view) {
331332
OneSignal.sendOutcome(outcomeName.getText().toString(), new OneSignal.OutcomeCallback() {
332333
@Override
333-
public void onSuccess(OutcomeEvent outcomeEvent) {
334-
updateTextView(outcomeEvent.toString());
334+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
335+
if (outcomeEvent != null)
336+
updateTextView(outcomeEvent.toString());
335337
}
336338
});
337339
}
338340

339341
public void onSendUniqueOutcomeClicked(View view) {
340342
OneSignal.sendUniqueOutcome(outcomeUnique.getText().toString(), new OneSignal.OutcomeCallback() {
341343
@Override
342-
public void onSuccess(OutcomeEvent outcomeEvent) {
343-
updateTextView(outcomeEvent.toString());
344+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
345+
if (outcomeEvent != null)
346+
updateTextView(outcomeEvent.toString());
344347
}
345348
});
346349
}
@@ -351,8 +354,9 @@ public void onSendOutcomeWithValueClicked(View view) {
351354

352355
OneSignal.sendOutcomeWithValue(outcomeValueName.getText().toString(), Float.parseFloat(outcomeValue.getText().toString()), new OneSignal.OutcomeCallback() {
353356
@Override
354-
public void onSuccess(OutcomeEvent outcomeEvent) {
355-
updateTextView(outcomeEvent.toString());
357+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
358+
if (outcomeEvent != null)
359+
updateTextView(outcomeEvent.toString());
356360
}
357361
});
358362
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3149,8 +3149,14 @@ private static boolean isValidOutcomeEntry(String name) {
31493149
return true;
31503150
}
31513151

3152+
/**
3153+
* OutcomeEvent will be null in cases where the request was not sent:
3154+
* 1. OutcomeEvent cached already for re-attempt in future
3155+
* 2. Unique OutcomeEvent already sent for ATTRIBUTED session and notification(s)
3156+
* 3. Unique OutcomeEvent already sent for UNATTRIBUTED session during session
3157+
*/
31523158
public interface OutcomeCallback {
3153-
void onSuccess(OutcomeEvent outcomeEvent);
3159+
void onSuccess(@Nullable OutcomeEvent outcomeEvent);
31543160
}
31553161
/*
31563162
* End OneSignalOutcome module

OneSignalSDK/onesignal/src/main/java/com/onesignal/OutcomeEventsController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ void sendUniqueOutcomeEvent(@NonNull final String name, @Nullable OneSignal.Outc
122122
"\nSession: " + osSessionManager.getSession().toString() +
123123
"\nOutcome name: " + name +
124124
"\nnotificationIds: " + notificationIds);
125+
126+
// Return null within the callback to determine not a failure, but not a success in terms of the request made
127+
if (callback != null)
128+
callback.onSuccess(null);
129+
125130
return;
126131
}
127132

@@ -134,6 +139,11 @@ void sendUniqueOutcomeEvent(@NonNull final String name, @Nullable OneSignal.Outc
134139
"Measure endpoint will not send because unique outcome already sent for: " +
135140
"\nSession: " + osSessionManager.getSession().toString() +
136141
"\nOutcome name: " + name);
142+
143+
// Return null within the callback to determine not a failure, but not a success in terms of the request made
144+
if (callback != null)
145+
callback.onSuccess(null);
146+
137147
return;
138148
}
139149

@@ -167,6 +177,7 @@ void onSuccess(String response) {
167177
else
168178
saveUnattributedUniqueOutcomeEvents();
169179

180+
// The only case where an actual success has occurred and the OutcomeEvent should be sent back
170181
if (callback != null)
171182
callback.onSuccess(outcomeEvent);
172183
}
@@ -186,6 +197,10 @@ public void run() {
186197
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.WARN,
187198
"Sending outcome with name: " + name + " failed with status code: " + statusCode + " and response: " + response +
188199
"\nOutcome event was cached and will be reattempted on app cold start");
200+
201+
// Return null within the callback to determine not a failure, but not a success in terms of the request made
202+
if (callback != null)
203+
callback.onSuccess(null);
189204
}
190205
};
191206

OneSignalSDK/onesignal/src/unity/java/com/onesignal/OneSignalUnityProxy.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.json.JSONException;
3333
import org.json.JSONObject;
3434

35+
import android.support.annotation.Nullable;
36+
3537
import com.onesignal.OneSignal.NotificationOpenedHandler;
3638
import com.onesignal.OneSignal.NotificationReceivedHandler;
3739
import com.onesignal.OneSignal.GetTagsHandler;
@@ -264,6 +266,42 @@ public void pauseInAppMessages(boolean pause) {
264266
OneSignal.pauseInAppMessages(pause);
265267
}
266268

269+
public void sendOutcome(String name) {
270+
OneSignal.sendOutcome(name, new OneSignal.OutcomeCallback() {
271+
@Override
272+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
273+
if (outcomeEvent == null)
274+
unitySafeInvoke("onSendOutcomeSuccess", "");
275+
else
276+
unitySafeInvoke("onSendOutcomeSuccess", outcomeEvent.toJSONObject().toString());
277+
}
278+
});
279+
}
280+
281+
public void sendUniqueOutcome(String name) {
282+
OneSignal.sendUniqueOutcome(name, new OneSignal.OutcomeCallback() {
283+
@Override
284+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
285+
if (outcomeEvent == null)
286+
unitySafeInvoke("onSendOutcomeSuccess", "");
287+
else
288+
unitySafeInvoke("onSendOutcomeSuccess", outcomeEvent.toJSONObject().toString());
289+
}
290+
});
291+
}
292+
293+
public void sendOutcomeWithValue(String name, float value) {
294+
OneSignal.sendOutcomeWithValue(name, value, new OneSignal.OutcomeCallback() {
295+
@Override
296+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
297+
if (outcomeEvent == null)
298+
unitySafeInvoke("onSendOutcomeSuccess", "");
299+
else
300+
unitySafeInvoke("onSendOutcomeSuccess", outcomeEvent.toJSONObject().toString());
301+
}
302+
});
303+
}
304+
267305
@Override
268306
public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) {
269307
unitySafeInvoke("onOSPermissionChanged", stateChanges.toJSONObject().toString());

0 commit comments

Comments
 (0)