Notification Runtime Permission (Android)
Android 13 (API level 33) and higher supports runtime permission for sending non-exempt (including Foreground Services (FGS)) notifications from an app. We recommend targeting Android 13 or higher as soon as possible to benefit from this feature's additional control and flexibility. Click here to learn more about push prompt notification permission.
Import Package
import { NotifyVisitors, PushPromptInfo } from 'capacitor-plugin-notifyvisitors';
Add the undermentioned code to your class
let pushPromptInfo = new PushPromptInfo();
pushPromptInfo.setTitle = "Test Title";
pushPromptInfo.setTitleTextColor = "#000000";
pushPromptInfo.setDescription = "Enable Push Notifications on Your Device !!";
pushPromptInfo.setDescriptionTextColor = "#000000";
pushPromptInfo.setBackgroundColor = "#EBEDEF";
pushPromptInfo.setButtonOneBorderColor = "#6db76c";
pushPromptInfo.setButtonOneBackgroundColor = "#26a524";
pushPromptInfo.setButtonOneBorderRadius = 0;
pushPromptInfo.setButtonOneText = "Allow";
pushPromptInfo.setButtonOneTextColor = "#FFFFFF";
pushPromptInfo.setButtonTwoText = "Cancel";
pushPromptInfo.setButtonTwoTextColor = "#FFFFFF";
pushPromptInfo.setButtonTwoBackgroundColor = "#FF0000";
pushPromptInfo.setButtonTwoBorderColor = "#6db76c";
pushPromptInfo.setButtonTwoBorderRadius = 0;
pushPromptInfo.setNumberOfSessions = 3;
pushPromptInfo.setResumeInDays = 1;
pushPromptInfo.setNumberOfTimesPerSession = 6;
NotifyVisitors.pushPermissionPrompt(pushPromptInfo).then(
(value: any) => {
console.log(value);
});
Notice that there are two parameters in the function above namely numberOfSessions and resumeInDays. These two parameters will handle the flow of SDK’s push prompt permission (not system’s permission dialog).
numberOfSessions → This parameter takes integer as input. In NV SDK, new or next session is created either on first app launch or after 30 minutes of user’s inactivity. So, if you set 3, then prompt will be displayed for next 3 sessions including current session in case user denies the prompt in every attempt.
resumeInDays → This parameter takes integer as input. When numberOfSessions set by you is completed then resumeInDays parameter will work. This is used to control the time period in days after which you intend to show the prompt again to the user. So, if you set 10 then prompt will remain hidden for 10 days and from the 11th day onwards it will get displayed according to the condition set in numberOfSessions parameter.
Callback responses
STATUS
|
MESSAGE
|
Success |
Popup launched. User granted permission. |
Success |
Push permission is already active on this device. |
Fail |
According to the resumeInDays set by the user, next popup will be shown after <day> day(s). |
Fail |
Session count for popup set by the user has been exceeded. Next popup will resume after resumeInDays condition falls false. |
Fail
|
Session count for popup set by the user has been exceeded. Next popup will resume after resumeInDays condition falls false.
|
Fail
|
Popup launched. User denied SDK's custom popup permission.
|
Fail
|
Popup launched. User denied permission.
|
Fail
|
Something went wrong with error --> <error>
|
Error
|
Failed with error :: <error>
|
Error
|
Something went wrong while launching popup with error :: <error>
|
Error
|
Something went wrong with error -----> <error>
|
Output with callback
{
"status":"success",
"message":"Popup launched. User granted permission."
}
Updated about 1 month ago