`Hi guys i have a problem about expo-notifications .
I am creating a reminder app and i need scheduled notifications.I created scheduled notification function and that’s main work about triggers.This is works on EXPO GO but not working on development build :android.(error:Calendars not support on android) . This is my schedulenotification function and js page :`
import * as Notifications from "expo-notifications";
import * as Calendar from "expo-calendar";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Platform } from "react-native";
import { saveToLocalNotification } from "../services/NotificationService";
import Toast from "react-native-toast-message";
import Constants from "expo-constants";
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
export const registerForPushNotificationsAsync = async () => {
if (Platform.OS === "android") {
await Notifications.setNotificationChannelAsync("default", {
name: "default",
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: "#FF231F7C",
});
}
const { status: existingStatus } = await Notifications.getPermissionsAsync({
projectId: Constants.expoConfig.extra.eas.projectId,
});
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync({
projectId: Constants.expoConfig.extra.eas.projectId,
});
finalStatus = status;
}
if (finalStatus !== "granted") {
alert("Failed to get push token for push notification!");
return;
}
const token = (
await Notifications.getExpoPushTokenAsync({
projectId: Constants.expoConfig.extra.eas.projectId,
})
).data;
await AsyncStorage.setItem(`pushToken`, JSON.stringify(token));
return token;
};
export const **scheduleNotificationAsync **= async (
type,
date,
content,
data = null
) => {
try {
if (!(date instanceof Date) || isNaN(date)) {
throw new Error("Invalid date parameter");
}
const targetDate = new Date(date);
const now = new Date();
let trigger = {};
const getTimeDiffInSeconds = (target, current) =>
(target.getTime() - current.getTime()) / 1000;
switch (type) {
case "D":
trigger = {
hour: targetDate.getHours(),
minute: targetDate.getMinutes(),
repeats: true,
};
break;
case "W":
trigger = {
weekday: targetDate.getDay(),
hour: targetDate.getHours(),
minute: targetDate.getMinutes(),
repeats: true,
};
break;
case "M":
trigger = {
day: targetDate.getDate(),
hour: targetDate.getHours(),
minute: targetDate.getMinutes(),
repeats: true,
};
break;
case "Y":
trigger = {
month: targetDate.getMonth() + 1,
day: targetDate.getDate(),
hour: targetDate.getHours(),
minute: targetDate.getMinutes(),
repeats: true,
};
break;
case "N":
trigger = {
seconds: getTimeDiffInSeconds(targetDate, now),
repeats: false,
};
break;
default:
trigger = {
seconds: getTimeDiffInSeconds(targetDate, now),
repeats: false,
};
break;
}
const notificationId = await Notifications.scheduleNotificationAsync({
content: {
...content,
data: data,
},
trigger,
});
return notificationId;
} catch (error) {
console.error("Failed to schedule notification:", error);
throw error; // Re-throw the error to handle it at the call site if needed
}
};
Why am i getting error on dev build and why this is works nice on expo go ? I know expo go is different but docs says android have yearly,monthly trigger .. 🙁