Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-4182 Prompt for push permission in JSInterface #387

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CleverTapSDK/CleverTapJSInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "CTInAppDisplayViewController.h"

#import "CleverTapBuildInfo.h"
#import "CleverTap+PushPermission.h"

@interface CleverTapJSInterface (){}

Expand Down Expand Up @@ -87,6 +88,11 @@ - (void)handleMessageFromWebview:(NSDictionary<NSString *,id> *)message forInsta
[cleverTap profileDecrementValueBy: message[@"value"] forKey: message[@"key"]];
} else if ([action isEqual: @"triggerInAppAction"]) {
[self triggerInAppAction:message[@"actionJson"] callToAction:message[@"callToAction"] buttonId:message[@"buttonId"]];
} else if ([action isEqual: @"promptForPushPermission"]) {
if (self.controller) {
[self.controller hide:NO];
}
[cleverTap promptForPushPermission:message[@"showFallbackSettings"]];
}
}

Expand Down
14 changes: 14 additions & 0 deletions ObjCStarter/ObjCStarter/sampleHTMLCode.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h2><center>CleverTap Webview</center></h2><br></br>
<p id="profileIncrementValueBy"> </p>
<button onclick="profileDecrementValueBy()">Decrement profile value</button>
<p id="profileDecrementValueBy"> </p>
<button onclick="promptForPushPermission()">Prompt for push permission</button>
<p id="promptForPushPermission"> </p>

<script>
function myFunction() {
Expand Down Expand Up @@ -151,6 +153,18 @@ <h2><center>CleverTap Webview</center></h2><br></br>
}
}

function promptForPushPermission() {
document.getElementById("promptForPushPermission").innerHTML = 'Prompted for push permission';
const message = {
action: 'promptForPushPermission',
showFallbackSettings: true
};

if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.com_clevertap_ObjCStarter) {
window.webkit.messageHandlers.com_clevertap_ObjCStarter.postMessage(message);
}
}


</script>

Expand Down
14 changes: 14 additions & 0 deletions SwiftStarter/SwiftStarter/Supporting Files/sampleHTMLCode.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h2><center>CleverTap Webview</center></h2><br></br>
<p id="profileIncrementValueBy"> </p>
<button onclick="profileDecrementValueBy()">Decrement profile value</button>
<p id="profileDecrementValueBy"> </p>
<button onclick="promptForPushPermission()">Prompt for push permission</button>
<p id="promptForPushPermission"> </p>

<script>
function myFunction() {
Expand Down Expand Up @@ -151,6 +153,18 @@ <h2><center>CleverTap Webview</center></h2><br></br>
}
}

function promptForPushPermission() {
document.getElementById("promptForPushPermission").innerHTML = 'Prompted for push permission';
const message = {
action: 'promptForPushPermission',
showFallbackSettings: true
};

if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.com_clevertap_demo) {
window.webkit.messageHandlers.com_clevertap_demo.postMessage(message);
}
}


</script>

Expand Down
Loading