Expo BackgroundFetch not working on android when app is terminated - background

The task gets registered it also works.When in recent apps it works.When gets deleted it stops working!
Expo CLI 3.11.3 environment info:
System:
OS: Windows 10
Binaries:
Yarn: 1.21.0 - C:\Users\Steve\AppData\Roaming\npm\yarn.CMD
npm: 6.9.0 - E:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.5.0.0 AI-191.8026.42.35.5900203
SDK version : 36.0.0
Standalone app on android 7
Just to confirm I was right I went into my apps background in my setting in my phone,I can see the app is in background progress.As soon as I remove it from recent apps it gets gone from the background progress too.So everything is as I described and no doubts about it.I also have used:
stopOnTerminate: false,
But it doesn’t do anything.
Here’s a function that does register the tasks and everything:
import * as BackgroundFetch from 'expo-background-fetch';
import * as TaskManager from 'expo-task-manager';
export async function registerFetchTask(taskName, jobCallback, interval) {
TaskManager.defineTask(taskName, jobCallback);
const status = await BackgroundFetch.getStatusAsync();
switch (status) {
case BackgroundFetch.Status.Restricted:
case BackgroundFetch.Status.Denied:
console.log("Background execution is disabled");
return;
default: {
console.log("Background execution allowed");
let tasks = await TaskManager.getRegisteredTasksAsync();
if (tasks.find(f => f.taskName === taskName) == null) {
console.log("Registering task");
await BackgroundFetch.registerTaskAsync(taskName,{
minimumInterval: 60,
stopOnTerminate: false,
startOnBoot: true,
});
tasks = await TaskManager.getRegisteredTasksAsync();
console.log("Registered tasks", tasks);
} else {
console.log(`Task ${taskName} already registered, skipping`);
}
console.log("Setting interval to", interval);
await BackgroundFetch.setMinimumIntervalAsync(interval);
}
}
}
Inside app.js I call:
registerFetchTask('wow',()=>{
fetchServer('/test',{});
console.log('WOWWW HIIIIIIIII YGNNNNNN');
},5);
The fetchServer will add things to my database on my laptop.So I can see if the app is running the task I’m getting new rows in the database.

Related

React Native Fetch Blob/React Native Blob Util Fail in Production but not in Developer time

I am trying to download a pdf generated through an own api that worked normally for me until yesterday, since then it has stopped working without any modification. Reviewing in developer mode through the metro everything seems to work correctly without any problems (I download the pdf normally), but when deploying the application in the playstore it closes unexpectedly, leaving me without knowing why this happens.
First I was using the React Native Fetch Blob, then I used React Native Blob Util hoping it would solve the problem but it keeps happening. Do you guys have any ideas for why does this happen?
The PDF file download this function:
const generarReciboPdf = async (datosDeuda:FormularioScreenParams,formaPago:ReactText,nroCheque?:string) =>{
const{config,fs} = ReactNativeBlobUtil
if (formaPago === 4 && (nroCheque == ""|| undefined)) {
return console.log('debe llenar todos los campos');
}
const { DownloadDir } = fs.dirs;
const token = await AsyncStorage.getItem('token');
let datosDeudaCompleto= {
...datosDeuda,
forma_pago:formaPago,
nro_cheque:nroCheque
}
let url = 'https://sys.arco.com.py/api/appRecibos/generarReciboPdf/'+JSON.stringify(datosDeudaCompleto)
// return console.log(url);
const options = {
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true, // true will use native manager and be shown on notification bar.
notification: true,
mime:'application/pdf',
path: `${DownloadDir}/recibo_${datosDeuda.mes_deuda.replace(/ /g, "")}_${datosDeuda.razon_social.replace(/ /g, "")}.pdf`,
description: 'Downloading.',
},
};
config(options).fetch('GET', url,{Authorization :'Bearer '+token}).then((res) => {
console.log('se imprimio correctamte el pdf');
setErrorPdf(1)
}).catch((error)=>{
console.log(error);
setErrorPdf(-1);
});
}
Also, this error appears in Play Console: "PlayConsole Error Image".
PlayConsole Error Image

useURL hook expo-linking for background app

The expo-linking React Native package has a hook named useURL that isn't working for me when the app is in the background. From the docs it Returns the initial URL followed by any subsequent changes to the URL. The problem I'm having with my managed expo app is that the hook doesn't work when the app is already open in the background. Here is the hook:
export default function App() {
const isLoadingComplete = useCachedResources();
const url = Linking.useURL();
useEffect(() => {
Alert.alert(url ? url.substring(20) : 'null');
}, [url]);
if (!isLoadingComplete) {
return null;
} else {
return (
...
);
}
}
If I open the URL exp://exp.host/#myprofile/myproject?a=bwhen the app is closed, I get an Alert as expected. If the app is in the background, the Alert doesn't go off. I've tested on an iOS emulator and a physical Android. Any solutions? Note that similar problems happen with Linking.addEventListener().

Expo client restart because of DocumentPicker

Expo client app reload/restart after selecting file via DocumentPicker!
Expo SDK Version: 32.0.0
Sample code trying to run, https://snack.expo.io/HkuSxz6Sf
It doesn't provide an error either, it just restarts again!
Please add the code below
async componentDidMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
}

Ionic 3 / AngularFire2 authState not persisting on Android (but works on Web)

Hey all so this is kind of driving me crazy.
Here is the code:
constructor(
platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
afAuth: AngularFireAuth
) {
afAuth.authState.subscribe(user => {
if (user) {
this.rootPage = "TabsPage";
console.log("logging in");
console.log(JSON.stringify(user)); // user
} else {
this.rootPage = "LoginPage";
console.log("logging out");
console.log(JSON.stringify(user)); // null
}
});
When run on the web I can login to my app and then log out as expected. However on Android (testing via ionic cordova run android) the user subscription is set and then immediately set to null.
So I figured it out!
It was the version of firebase that I was using v4.12.1
I changed to version 4.11.0 and the problem stopped occuring.

How to show native popup using Gulp

I am working on Gulp build process for automation. I have created a Gulp task for creating signed APK of android. Now I want to show a notification popup so that I can come to know my android APK is built.
Is there any way to show native popup in Gulp process?
I have done research and found node-notifier and gulp-notify modules but both are not working for me. Please help
As per posted answer,
I have tried with following, but no help... I am not getting notification. Does it requires Windows Toaster Support... I am using Windows 8.1 Pro.
gulp.task('notifier', function(){
notify('Running from notifier task', 'Everything looks good');
});
function notify(title, message) {
// Load dependencies
var path = require('path');
var notifier = require('node-notifier');
var notifyOptions = {
title: title,
message: message,
//icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
wait: true // Wait with callback, until user action is taken against notification
};
// start notifier
notifier.notify(notifyOptions);
}
Try this:
Make sure these are installed by running install once again
Install
npm install path node-notifier --save-dev
Task
gulp.task('notifier', function(){
notify('Running from notifier task', 'Everything looks good');
);
Notifier Function
function notify(title, message) {
// Load dependencies
var path = require('path');
var notifier = require('node-notifier');
var notifyOptions = {
title: title,
message: message,
icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
wait: true // Wait with callback, until user action is taken against notification
};
// start notifier
notifier.notify(notifyOptions);
}
This is too late after asking the question, but I thought it's good to record my solutions here.
So there are different commands to show a native popup for different OS.
1. Windows
Use the command msg * <Your_Message_Here>, for example, msg * Hello World.
This popup closes automatically after 1 minute.
2.iOS
Use the command
osascript -e 'tell app \"System Events\" to display dialog \"<Your_Message>\" with title \"<Your_Title>\"'"
and then you can execute these commands using node exec,
var WINDOWS_POPUP = "msg * MESSAGE";
var MAC_POPUP = "osascript -e 'tell app \"System Events\" to display dialog \"MESSAGE\" with title \"SUCCESS\"'";
function execCMD(cmd, cb) {
exec(cmd,
{
cwd: './',
maxBuffer: 2048 * 2048
},
function (err, stdout, stderr) {
plugins.util.log(stdout);
plugins.util.log(stderr);
if (err) {
cb(err);
} else {
cb(null,stdout);
}
});
}
/**
* Rename android apk
*/
gulp.task('copyAPK', function () {
return gulp.src(APK_PATH)
.pipe(plugins.if(args.signedAPK, plugins.rename(APK_NAME)))
.pipe(gulp.dest(releaseDirName + '/Android/'))
.on('end', function () {
plugins.util.log(plugins.util.colors.green('Good Job! Your APK is ready at following location : ') + plugins.util.colors.cyan(releaseDirName + '/Android/' + APK_NAME))
execCMD(WINDOWS_POPUP.replace('MESSAGE', 'Good Job! Your APK is ready at following location : ' + releaseDirName + '/Android/' + APK_NAME), function () {
})
});
});
/**
* Copy generated IPA
*/
gulp.task('copyIPA', function () {
return gulp.src(IPA_PATH)
.pipe(plugins.rename(IPA_NAME))
.pipe(gulp.dest(releaseDirName + '/iOS/'))
.on('end', function () {
plugins.util.log(plugins.util.colors.green('Good Job! Your IPA is ready at following location : ') + plugins.util.colors.cyan(releaseDirName + '/iOS/' + IPA_NAME))
execCMD(MAC_POPUP.replace('MESSAGE', 'Good Job! Your IPA is ready at following location : ' + releaseDirName + '/iOS/' + IPA_NAME), function () {
})
});
})
Hope this will help someone in scripting :).