The Native App Install Banner doesn't let us know if user has cancelled or installed the Native App in mobile devices, by using the below code. Please Help.
deferredPrompt.userChoice.then(function(choiceResult) {
console.log('User Choice!');
console.log(choiceResult.outcome);
choiceElement.textContent = choiceResult.outcome;
if(choiceResult.outcome == 'dismissed') {
console.log('Cancelled Install');
}
else {
console.log('User added to homescreen');
}
// We no longer need the prompt. Clear it up.
deferredPrompt = null;
});
Related
I have an expo managed app with a button on the screen, when the button is pressed several API calls are made to my backend and finally after the last API call depending on whether the Platform OS is ios or android i would like the app to navigate to a specific screen.
On IOS, everything is working accordingly.
On Android, the expo app crashes and closes before navigating to the next screen.
Here is my onButtonClick function:
const handlePayment=async()=>{
setLoading(true);
const sessionResponse = await paymentApi.paymentSession(
selected,route.params.transaction.id,cvv
);
if(!sessionResponse.ok){
setLoading(false)
if(sessionResponse.data){
Alert.alert(sessionResponse.data.error)
}else{
Alert.alert("Unexpected Error Occurred while creating session.")
}
}
console.log('create and update session',sessionResponse)
if(sessionResponse.data.session.updateStatus==='SUCCESS'){
const initiateResponse = await paymentApi.initiateAuthentication(
sessionResponse.data.session.id,route.params.transaction.id
);
if(!initiateResponse.ok){
setLoading(false)
if(initiateResponse.data){
Alert.alert(initiateResponse.data.error)
}else{
Alert.alert("Unexpected Error Occurred while initiating authentication")
}
}
console.log('Initiate Authentication',initiateResponse.data);
if(initiateResponse.data.result==='SUCCESS'){
setInitiateWebView(true);
const redirectHTML=(initiateResponse.data.authentication.redirectHtml).replace(/\\/g, '');
setInitiateWebViewUrl(redirectHTML);
console.log('session id ', sessionResponse.data.session.id)
const authenticateResponse = await paymentApi.authenticatePayer(
sessionResponse.data.session.id,route.params.transaction.id
);
if(!authenticateResponse.ok){
setLoading(false)
if(Platform.OS !== 'ios'){
clearInterval(myInterval)
}
Alert.alert("Unexpected Error Occurred","Please try again")
}
console.log('authenticate payer',authenticateResponse.data)
const authenticationResponseData = authenticateResponse.data;
console.log('authenticate payer authenticate data',authenticationResponseData.authentication);
const payerInteraction = authenticationResponseData.authentication.payerInteraction;
if(authenticationResponseData.authentication['3ds2']){
const status = authenticationResponseData.authentication['3ds2'].transactionStatus;
if(payerInteraction==='REQUIRED'&&status==="C"){
console.log("Challenge Flow")
setAuthenticateWebViewUrl(authenticationResponseData.authentication.redirectHtml.replace(/\\/g, ''))
console.log('Auth webview url::::::',authenticationResponseData.authentication.redirectHtml.replace(/\\/g, ''))
----> this is the last thing that appears on console before android app crashes
if(Platform.OS==='ios'){
setLoading(false);
navigation.navigate(routes.PAYWITHTOKEN,{html:authenticationResponseData.authentication.redirectHtml.replace(/\\/g, '')})
}else {
setLoading(false);
navigation.navigate(routes.PAYWITHTOKENANDROID)
}
}
The other screen is just a blank screen. I have tried navigating to that screen somewhere else inside my app and its working. The problem is here.
Follow instructions for watch logcat:
Open android studio
My website currently sends push notifications to users when accessing the site for the first time, is there a way to remove this push notification request?
TIA
Use this in your .js file
Notification.requestPermission();
Create a button for "Enable Notification" in .html file
<button id="enable">Enable notifications</button>
When pressing this button app requests notification for the app (.js file)
function askNotificationPermission() {
// Asking for permissions
function handlePermission(permission) {
// button set for shown or hidden, depending on the user's selection
if(Notification.permission === 'denied' || Notification.permission === 'default') {
notificationBtn.style.display = 'block';
} else {
notificationBtn.style.display = 'none';
}
}
// Check if the browser actually supports notifications
if (!('Notification' in window)) {
console.log("This browser does not support notifications.");
} else {
if(checkNotificationPromise()) {
Notification.requestPermission()
.then((permission) => {
handlePermission(permission);
})
} else {
Notification.requestPermission(function(permission) {
handlePermission(permission);
});
}
}
}
I;m trying to implement a pwa application on a small site and i need to addToHomeScreen button. It works fine on chrome mobile and desktop but not on native Android browser or Safari.
The code is this:
window.onload = () => {
'use strict';
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.js');
}
}
let installPromptEvent;
btnInstall=document.querySelector(".add-button");
window.addEventListener('beforeinstallprompt', (event) => {
console.log("before");
// Prevent Chrome <= 67 from automatically showing the prompt
event.preventDefault();
// Stash the event so it can be triggered later.
installPromptEvent = event;
// Update the install UI to notify the user app can be installed
document.querySelector('.add-button').style.display= "block";
});
btnInstall.addEventListener('click', () => {
// Update the install UI to remove the install button
document.querySelector('.add-button').style.display= "none";
// Show the modal add to home screen dialog
//installPromptEvent.prompt();
if (installPromptEvent) {
installPromptEvent.prompt();
installPromptEvent.userChoice.then((choice) => {
if (choice.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
// Clear the saved prompt since it can't be used again
installPromptEvent = null;
});
}
<button class="add-button">Instaleaza aplicatia</button>
Can anyone to help me?
Thanks
I want to send the desktop notification to my customer dynamical from the server side. For example I have one website based on the e-commerce platform. I want to send the desktop notification to my customer what are the new offers are available. I created the notification with following code.. But I want to call the notification without any user activity.
$(window).load(function(){
if(!window.Notification){
console.log('sorry Notification not supported');
}
else {
Notification.requestPermission(function(p){
if(p === 'denied') {
} else if(p === 'granted') {
} else {
}
console.log(p);
});
}
var notify;
if(Notification.permission === 'default') {
console.log('Please allow Notification');
} else {
notify = new Notification('Cashback Notification..',{
body : 'Get assured cashback on purchases made via Getex.com',
icon : 'images/notification_getex.png'
});
}
});
Here i trigger notification only for the window load, but i want to notify from the server side like execute or call any API link.
Please help me Thanks!
I've run into a weird issue using Titanium 3.2.0.GA and the Facebook module. When I try calling fb.authorize(); and if I'm logged into Facebook through iOS 7, the dialog pops up asking if I would like to allow it to blah blah blah. But once I tap "Allow", it triggers the login event with code -1, and is unsuccessful. However, if I'm not logged into Facebook through iOS 7, and login to Facebook through Safari after calling fb.authorize();, everything works as expected and the login event is triggered successfully.
var fb = require('facebook');
fb.appid = ****;
fb.permissions = ['email'];
fb.forceDialogAuth = false;
fb.addEventListener("login", function(e) {
if (fb.success && fb.accessToken != null) {
console.log(fb.accessToken);
}
});
And like I said above, when the Facebook button is pressed I just call fb.authorize();.
Is anyone else having issues like this on iOS 7 using Titanium?
Looks like I fixed it. On my Facebook app, I had to add an iOS app and turn the "Single Sign On" on. Facebook was having issues last night and wouldn't let me make changes to my app but I just tried it today and it works now. I think this might be something new for iOS 7, but I'm not sure. However, turning Single Sign On to On worked for me.
Just declare All bellow variables in calling function only not globally other wise each time it will call fb.authorize().
i.e
var fb = null;
function facbooksharing(sharingData){
if(fb == null){
fb = require('facebook');
fb.appid = "******";
fb.permissions = ['publish_stream', 'read_stream','publish_actions'];
fb.forceDialogAuth = true; `enter code here`
}
if(fb.loggedIn==true)
{
fb.dialog("feed", sharingData, showRequestResult);
}else{
fb.authorize();
}
function showRequestResult(e)
{
if (e.success)
{
if (e.result)
{
Ti.API.info("Data Shared between your friend successfully.");
}
}
}
fb.addEventListener("login", function(e) {
if (fb.success && fb.accessToken != null) {
console.log(fb.accessToken);
}
});
}
Let me know is this resolve your problem or not.