Maximum limit of concurrent alarms 500 reached for uid: u0a32

170 views Asked by At

Getting this crash in my firebase console: Maximum limit of concurrent alarms 500 reached for uid when creating more than 500 alarms in the React Native app.

Following is the code:

let scheduledTime = moment(
  day.format('DD-MM-YYYY') +
    ' ' +
    moment(obj?.reminder_time).format('HH:mm'),
  'DD-MM-YYYY HH:mm',
).toISOString();

if (moment(scheduledTime).isAfter(moment())) {
  const trigger = {
    type: TriggerType.TIMESTAMP,
    timestamp: moment(scheduledTime).valueOf(),
    alarmManager: true,
    alarmManager: {
      allowWhileIdle: true,
    },
  };

  await notifee.createTriggerNotification(
    {
      title: obj?.name,
      body: "Please complete your today's habit",
      data: {
        type: 'habit',
        _id: obj?._id,
      },
      android: {
        channelId: 'default',
        smallIcon: 'ic_stat_notification',
        pressAction: {
          id: 'default',
          launchActivity: 'default',
          launchActivityFlags: [AndroidLaunchActivityFlag.SINGLE_TOP],
        },
      },
      ios: {
        badgeCount: (await notifee.getBadgeCount()) + 1,
      },
    },
    trigger,
  );

Kindly help me to fix this.

1

There are 1 answers

1
Umer Aftab On

Creating 500 alarms in a React Native app can be a substantial task, and it's essential to approach it efficiently to ensure your app remains responsive and doesn't negatively impact the device's performance. Here's a high-level overview of how you can create a large number of alarms:

  1. Data Storage: First, you need to decide how to store your alarms. You could use a database like SQLite, AsyncStorage, or an external server to manage the alarms. Storing them in memory might not be efficient for a large number of alarms.

  2. Data Structure: Define a data structure to represent alarms. Each alarm should include information such as the time, title, and any other relevant details.

  3. User Interface: Decide how users will set these alarms. You might want to create a user interface to add, edit, and delete alarms. This UI could be a list of alarms with the option to create or edit them.

  4. Scheduling Alarms:

    a. To create a large number of alarms, you can use a scheduling library like react-native-background-job or the built-in react-native-push-notification library.

    b. You'll need to loop through your alarm data and schedule each alarm individually. Ensure that you handle potential scheduling conflicts (e.g., alarms at the same time) and manage them accordingly.

    c. Consider batching the scheduling process for better performance. Instead of scheduling all 500 alarms at once, you could schedule them in smaller batches over time or in response to user interactions.

  5. Handling Alarms:

    a. Implement logic to handle alarms when they trigger. This might involve showing a notification, playing a sound, or any other action you want the app to take when an alarm goes off.

    b. Make sure you handle cases where the app is not running or in the background. You may need to use background tasks or services to ensure alarms trigger even if the app is closed.

  6. Performance Considerations:

    a. Creating a large number of alarms can potentially impact the performance and battery life of the device. Be mindful of these considerations.

    b. You might need to optimize your app to ensure it doesn't consume excessive resources. This could involve deferring the scheduling of less urgent alarms and ensuring alarms are efficiently stored and retrieved from storage.

  7. Testing: Thoroughly test your app with a large number of alarms to identify any potential issues with performance, reliability, and user experience.

  8. Error Handling: Implement error handling and recovery mechanisms for cases where alarms fail to schedule or trigger.

  9. User Feedback: Provide clear feedback to users when alarms are added, edited, or triggered.

Remember that creating 500 alarms is a resource-intensive task, and the feasibility of implementing this depends on the capabilities of the device and the constraints of the React Native platform. Ensure that your app remains responsive and doesn't degrade the user experience.