How To Repeat Notifications React Native - reactjs

I'm using this library for local notifications but for some reason, I can't get the notifications to repeat each day. Even with having "repeatType: day" in the object. Does anyone know how to repeat local notifications for iOS using this library?
Here's the code I currently wrote to do this:
var trigger = new Date();
trigger.setDate(trigger.getDate()+1);
trigger.setHours(7);
trigger.setMinutes(0);
trigger.setMilliseconds(0);
PushNotification.localNotificationSchedule({
message: "Your Daily Schedule is Ready.", // (required)
date: trigger, // in 60 secs
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
repeatType: "day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
});
trigger = new Date();
trigger.setDate(trigger.getDate());
trigger.setHours(22);
trigger.setMinutes(30);
trigger.setMilliseconds(0);
PushNotification.localNotificationSchedule({
message: "Your Evening Schedule is Ready.", // (required)
date: trigger, // in 60 secs
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
repeatType: "day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
});

Related

NPM react-native-custom-timer-notification

Hello friends, I'm in doubt, I was wondering if you guys can help me. I'm doing a project in React Native where I need push notifications to contain a timer/countdown and that they can pause/start tasks and that countdown. It's been a challenge for me. I would like to do as the notifications of the app Pomodoro, which pause tasks through them and warn you how much time is left to finish a task. I found nothing about on the internet
I just found the dependency react-native-custom-timer-notification in the NPM website, if you know any other dependency that you can do that, please pass me
Usage
payload sent will be received when click or canceled
title Title of the notification
body Body of the notification
id unique number
date Time at which zero comes
import { TimerNotification, onEvent } from "react-native-custom-timer-notification";
// ...
// onclick and cancel listner
onEvent(event=>{
console.log(event)
});
// Remove timer
RemoveTimer(160211114);
//Trigger notification
TimerNotification({
payload: JSON.stringify('notificationOpen?.data'),
title: 'My notification',
body: 'Much longer text that cannot fit one line... ',
id: 160211114,
remove: false, // optional
foreground: false,
date: new Date(Date.now() + 20000),
isCountDown: true, // false for positive timer
setCustomContentView:true // optional
});
now react-native-custom-timer-notification v0.8 supports full scale custom notification. i think this might help you in this case. https://www.npmjs.com/package/react-native-custom-timer-notification

Specify time of events sent with AppInsights?

Is there a way to set the time of events manually sent in App Insights? I'm using the ApplicationInsights package from #microsoft/applicationinsights-web in a react app. As an example, I want to execute something like this at 6:00pm ETC Apr 26, 2022:
appInsights.trackEvent({
name: "my cool event",
properties: {
greeting: "hello world"
},
});
But have it logged in my azure portal as happening at 5:00pm ETC Apr 26, 2022. I figured there would be a time property or something I could set on the parameter object, but that doesn't seem to be the case.
AFAIK, We have trackDependencyData, which is the IDependencyTelemetry interface, which has startTime as a parameter to know the telemetry event start time.
Sample code:-
var success = false;
var startTime = new Date().getTime();
try
{
success = dependency.Call();
}
finally
{
var elapsed = new Date() - startTime;
telemetry.trackDependency({
dependencyTypeName: "myDependency",
name: "myCall",
duration: elapsed,
success: success
});
}
For more information please refer the below links:-
MICROSOFT DOCUMENT| trackDependency , API SUMMARY
SO THREAD | Azure Application Insight JavaScript SDK trackEvent Timestamp

Discord.js Bot Status

No, I am not asking how to set my bot's status. I am asking how to make my bot's status change every 5-7 seconds to another status. How would I make this:
client.user.setActivity(`dsc.gg/ultraa | ?help | ${client.guilds.cache.size} servers`, { type: 'WATCHING' });
change every few seconds to be like "It's frosty out there", and "420 servers", and "?help | dsc.gg/ultraa". How would I make those statuses rotate between each other?
Note: This code is for Discord.js V13.3.1
For a rotating status, as you would describe, you would do this by placing some code in the ready event that changes the status after a set period of time. This will require the util package which can be installed using:
npm: npm install util
yarn: yarn install util
Once you have the package installed, you will create a function called wait. It's a simple way to wait without blocking the rest of the script.
const wait = require('util').promisify(setTimeout);
This function will serve our primary purpose, making the delay between switching the statuses. Then, we will use setInterval to continuously loop between the statuses.
<Client>.on('ready', async () => {
// ...
setInterval(async () => {
client.user.setPresence({ activities: [{ name: `Status1`, type: `PLAYING` }] });
await wait(5000); // Wait 5 seconds
client.user.setPresence({ activities: [{ name: `Status2`, type: `PLAYING` }] });
await wait(5000); // Wait 5 seconds
});
});
As you can see, there are two line that repeat themselves. That is: <Client>.user.setPresence(...) and await wait(5000). The wait function will block the status from updating itself too early. You can edit the amount of time set by converting the seconds to milliseconds (5 seconds becomes 5000). The other portion sets the bot's status. The type shows what the bot is doing. The valid values for this are found in the docs. You can simply copy and paste the two lines and add more statuses as needed.
client.user.setPresence({ activities: [{ name: `Status`, type: `PLAYING` }] });
For Simple Status

Coldfusion - Refreshing Page When A Database Record Updates

Good day,
Let me describe my problem :
Scenario :
User 1 has a coldfusion webpage, containing 6 alerts as html elements populated using a database. User 1 is constantly monitoring this page for changes.
A user on a different computer (different session) logs into a admin console and add's a 7th element and inserts it into the database.
The database contains a field that changes from 0 to 1 as soon as an alert is added and inserted into the database.
The webpage of User 1 not has to dynamically refresh or update with the 8th alert.
Problem :
I am struggling to run a async loop that queries the database permanently for the record that tells it there is a change, while not freezing the rest of the page.
Solution :
I need to run a cfquery to check the isUpdated field in the database.
That cfquery needs to be run every minute.
As soon as the cfquery returns a 1, the page should refresh which in turn will populate the new alert as well.
Can be done through sockets, and you do not have to check the availability of a new record every minute.
You can also do it with javascript/jquery:
<script>
var lastAlert = '#lastAlert#'; //last at the time of loading the page
setInterval(function() {
lastAlert = isUpdated(lastAlert);
}, 60000);
function isUpdated(lastAlert){
res = lastAlert;
$.ajax({
url: 'checkAlerts.cfm', //in this file do check for changes in the database. should return the number of the last alert
type: 'POST',
data: {lastAlert:lastAlert},
cache: false,
success:function(res){
if(res > lastAlert){
//your code if there is a new entry
alert('a new entry has been added');
}
}
});
return res;
}
</script>
I did not check the code! But I hope you understand how to proceed.

Background Geolocation Plugin: Track location and update database every 5 minutes

I'm currently developing a mobile app using AngularJS / Ionic 3.
I need to track at all time, if my users are within a radius of 100m of a certain geolocation (let's call it "Home Location". I need to know at all time which user is at his home location, and who is not (even when the app is running in background or is closed/ terminated).
I thought to realize this, using the Ionic Native Background-Geolocation plugin and the cordova-plugin-background-geolocation. My plan was, to check the users geolocation every 5 minutes and compare it to the home.
Case 1) If the distance between the two locations is < 100m I know the user is "at home". I would then update the user node in my database (Firebase) to mark the user as isAtHome: true and add a current timestamp.
Case 2) If the user is not within 100m of his home location I would mark him as isAtHome: false and add a current timestamp.
I need to update my database even in case the user didn't move, because I need to know that I received a current signal. Otherwise I don't know if he didn't move or turned off his smartphone, for example.
If I want to know, who of my users is at his home location, I would check the isAtHome-attributes and if they are set to true, I would check the timestamp to be sure that I have up-to-date data and the data was written within the last 15 minutes.
I tried many different things, but I'm not sure how to realize this with the Cordova Background Geolocation Plugin and if it's even possible.
My question is:
Is it possible to check the users geolocation every 5 minutes (even in background / terminated state) and call a function that updates my firebase DB accordingly? As described, I need to receive the location even if the user didn't move within the last 5 minutes.
If it isn't possible: Does anybody have an idea, of how to approach the requirements on another way?
Thank you very much for your help!
As described in the cordova-plugin-background-geolocation says, you can configure an interval in milliseconds for the plugin to get the location, see this example from the plugin github page:
backgroundGeolocation.configure(callbackFn, failureFn, {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
url: 'http://192.168.81.15:3000/locations',
httpHeaders: { 'X-FOO': 'bar' },
maxLocations: 1000,
// Android only section
locationProvider: backgroundGeolocation.provider.ANDROID_ACTIVITY_PROVIDER,
interval: 60000, // <-- here
fastestInterval: 5000,
activitiesInterval: 10000,
notificationTitle: 'Background tracking',
notificationText: 'enabled',
notificationIconColor: '#FEDD1E',
notificationIconLarge: 'mappointer_large',
notificationIconSmall: 'mappointer_small'
});
The case is this interval property works only for Android. I would sugest a workaround like this:
public getLocation: boolean = true; // CREATE A BOOLEAN TO KNOW IF YOU CAN GET LOCATION
backgroundGeolocation.start( // i've never used this plugin, so i'm assuming this is what starts de background watcher
() => {
if(getLocation == true){
this.getLocation = false; // SET TO FALSE SO IT DON'T DO YOUR FUNCTION THE NEXT TIME IT GETS THE LOCATION
// DO YOUR CODE TO SAVE AND CHECK YOUR DATA
// IT'S BETTER IF YOU USE A PROMISE, ASYNC/AWAIT FOR THE SAVING CODE
yourSavingCodeFunction().then(() => {
setTimeout(()=>{
// AFTER 5 MINUTES, SET THE GETLOCATION TO TRUE SO IT CAN DO YOUR FUNCTION AGAIN
this.getLocation = true;
}, 500000);
});
}
},
(error) => {
// Tracking has not started because of error
// you should adjust your app UI for example change switch element to indicate
// that service is not running
}
);
If you haven't thought about your cases 1 and 2 we can work on this too. Hope this helps or can give you some ideas :D

Resources