Skip to content

Commit

Permalink
Add notification permission prompting to IAMs
Browse files Browse the repository at this point in the history
Add support for notification permission prompting to In-App Messaging.
  • Loading branch information
jkasten2 committed Jun 24, 2022
1 parent 80f24a9 commit 4ea9662
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.ArrayList;
import java.util.List;

import static com.onesignal.OSInAppMessageLocationPrompt.LOCATION_PROMPT_KEY;

public class OSInAppMessageAction {

private static final String ID = "id";
Expand Down Expand Up @@ -117,8 +115,14 @@ private void parseOutcomes(JSONObject json) throws JSONException {
private void parsePrompts(JSONObject json) throws JSONException {
JSONArray promptsJsonArray = json.getJSONArray(PROMPTS);
for (int i = 0; i < promptsJsonArray.length(); i++) {
if (promptsJsonArray.get(i).equals(LOCATION_PROMPT_KEY) ) {
prompts.add(new OSInAppMessageLocationPrompt());
String promptType = promptsJsonArray.getString(i);
switch (promptType) {
case OSInAppMessagePushPrompt.PUSH_PROMPT_KEY:
prompts.add(new OSInAppMessagePushPrompt());
break;
case OSInAppMessageLocationPrompt.LOCATION_PROMPT_KEY:
prompts.add(new OSInAppMessageLocationPrompt());
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.onesignal;

public class OSInAppMessagePushPrompt extends OSInAppMessagePrompt {

static final String PUSH_PROMPT_KEY = "push";

@Override
void handlePrompt(OneSignal.OSPromptActionCompletionCallback callback) {
OneSignal.promptForPushNotifications(
true,
accepted -> {
OneSignal.PromptActionResult result = accepted ?
OneSignal.PromptActionResult.PERMISSION_GRANTED :
OneSignal.PromptActionResult.PERMISSION_DENIED;
callback.onCompleted(result);
}
);
}

@Override
String getPromptKey() {
return PUSH_PROMPT_KEY;
}

}

0 comments on commit 4ea9662

Please sign in to comment.