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
Related
I built a simple snake game by javascript-socket.io, it works in desktop nicely, but don't work in mobile(android).
and i don't know why?
error log in chrome browser in mobile:
my project link:
https://hamed8993.github.io/front
if you go to above link, you will see that it works in Desktop as we want,
but if go by Mobile(Android) will see that it do not works!
there are codes:
1)socket.io version : "socket.io": "2.3.0"
2)index.js module in back-End (that runs Socket.io for run snake Game in front-End):
const io = require("socket.io")();
io.on("connection", client => {
client.emit("init", { data: "Game Started!"})
startGameInterval(client);
});
function startGameInterval(client){
const intervalId = setInterval(() => {
client.emit("palse")
}, 400)
}
io.listen(3000);
3)index.js (for client page of index.html):
window.onload = () => {
//socket.io:
const socket = io("http://127.0.0.1:3000");
socket.on("init", (msg)=> console.log(msg) );
socket.on("palse", update);
// other functions, and "update" function...
}
this project Repository Address in gitHub:
https://github.com/hamed8993/hamed8993.github.io
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'm working on a electron(-nuxt) based application. End to End test re-written with AVA + Spectron. The .click() function however doesnt seem to work.
I used this template:
https://github.com/michalzaq12/electron-nuxt
Everything seems to work except a simple button click.
<footer class="modal-card-foot">
<button id="loginButton" class="button " type="button" #click="login">
Login
</button>
</footer>
test('app should login', async t => {
let app = t.context.app
await app.client.click('#loginButton')
})
The message i got is:
1 test failed
app should login
Error: Test finished without running any assertions
That is truthy because there aren't any assertions.
BUT i can see that the Button is never clicked, because that would trigger a "Login failed" message from the app.
In your test case you should wait for element to be rendered on the page.
test('app should login', async t => {
const ELEMENT_SELECTOR = '#loginButton'
let app = t.context.app
try {
await app.client.nuxt.ready()
await app.client.nuxt.navigate('/') //optional
await app.client.waitForExist(ELEMENT_SELECTOR)
await app.client.click(ELEMENT_SELECTOR)
t.pass() //or other assertion
} catch (e) {
t.fail(e.message)
}
})
Checkout this repo that is an example of how to test an electron app:
https://github.com/StephenDavidson/electron-spectron-example
specifically this where they test the functionality of pressing a button.
Notice how they import in the page at the top.
Search.js
const SearchPage = require('./page-objects/search.page');
Then near the bottom they test the functionality of click
it('should search', async() => {
const input = 'this is a test';
await app.client.url(config.url)
.setValue(SearchPage.searchField, input)
.getValue(SearchPage.searchField)
.should.eventually.equal(input)
.click(SearchPage.searchButton)
.element(SearchPage.searchResult)
.should.eventually.exist;
});
See if this helps you get further along.
Ive enabled deep linking and everything works great when the application opens. When I open the app from a closed state using the url moderatorapp://hello it logs the correct url, but it does not work when the app is deep linked while being opened from a background state. My code is as follows:
componentDidMount() {
// Storage.clear();
Storage.getItem('data_moderator')
.then(_data => {
if (_data && _data.tokens) {
this.autoLogin(_data.tokens);
} else {
Actions.loginForm();
}
}
);
Linking.getInitialURL()
.then(url => {
console.log('Initial Url then ', url);
if (url) {
console.log('Initial Url ', url);
}
})
.catch(error => console.log(error));
Linking.addEventListener('url', this.handleOpenURL);
}
This is obviously because the componentDidMount method is not being called at that point.
What I have tried:
I attempted to wrap the Linking code inside of an event that detects the application entering into the active state and it doesn't work, it logs the same url from the initial attempt when the app was closed. When I attempt to deep link into the app from the background state using the url moderatorapp://goodbye it logs the moderatorapp://hello. So it somehow is not updating.
AppState.addEventListener('change', (state) => {
if (state === 'active') {
console.log('state active');
Linking.getInitialURL()
.then(url => {
console.log('Initial Url then ', url);
if (url) {
console.log('Initial Url ', url);
}
})
.catch(error => console.log(error));
}
if(state === 'background'){
console.log('background');
}
});
Im really new to React Native, any assistance would be greatly appreciated.
Thanks.
https://facebook.github.io/react-native/docs/linking.html Specifically:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
Apple changed the api for linking so if you are targeting ios 9 or newer, you need this code in your AppDelegate.m file.
The deep linking is working as expected for me even the app is in background. Please check the below specifications.
Node Version : v12.18.x OR Greater
NPM Version : v6.14.x OR Greater
react-native-cli : 2.0.1
react-native : 0.63.x OR Greater
Please check if you have added below line in your AppDelegate.m.
#import <React/RCTLinkingManager.h>
It must be added above #ifdef FB_SONARKIT_ENABLED line. Adding it below this line will cause failing of build while Archiving it for release.
Please check if you have added below code in your AppDelegate.m which is responsible for deep linking.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
It will work for app cold boot, but it will not work if your app is in background. For this, you need to add below code in your AppDelegate.m
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id> *_Nullable))restorationHandler {
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
This should work irrespective of your AppState: active **OR** background.
This worked for me as expected! Give it a try. This is should definitely work.
Thanks in advance!
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;
});