我正在研究Expo日历和活动创建(Android + iOS) 一切都在Android expo应用程序中运行,但是当我使用以下命令构建apk时:expo build:android -t apk
启动apk时,没有崩溃,没有警告,也没有在日历中创建事件... 这是我的功能:
addEventCalendar = async (itemEventData) => {
const { status } = await Calendar.requestCalendarPermissionsAsync();
if (status === 'granted') {
let appCurrCalendar = await this.getAppCalendarSource();
let currCalendarId;
if (appCurrCalendar === undefined) {
// console.log('no cal --> create');
let currCalendar = await this.createCalendar();
currCalendarId = currCalendar;
} else {
currCalendarId = appCurrCalendar.id;
}
///check event
let startDate;
let endDate;
let detailsEvent;
if (Platform.OS === 'ios') {
startDate = moment(itemEventData.event_date + " " + itemEventData.event_hdeb).format("YYYY-MM-DD[T]HH:mm:ss.sssZ");
endDate = moment(itemEventData.event_date + " " + itemEventData.event_hfin).format("YYYY-MM-DD[T]HH:mm:ss.sssZ");
detailsEvent = {
title: itemEventData.titre_flyer + " - " + itemEventData.ville_agence,
startDate: moment(itemEventData.event_date + " " + itemEventData.event_hdeb).format("YYYY-MM-DD[T]HH:mm:ss.sssZ"),
endDate: moment(itemEventData.event_date + " " + itemEventData.event_hfin).format("YYYY-MM-DD[T]HH:mm:ss.sssZ"),
timeZone: Localization.timezone,
location: itemEventData.lib_agence + " " + itemEventData.adresse_agence + " - " + itemEventData.ville_agence + " " + itemEventData.cp_agence
}
} else {
startDate = moment(moment(itemEventData.event_date + " " + itemEventData.event_hdeb).valueOf());
endDate = moment(moment(itemEventData.event_date + " " + itemEventData.event_hfin).valueOf());
detailsEvent = {
title: itemEventData.titre_flyer + " - " + itemEventData.ville_agence,
startDate: moment(moment(itemEventData.event_date + " " + itemEventData.event_hdeb).valueOf()),
endDate: moment(moment(itemEventData.event_date + " " + itemEventData.event_hfin).valueOf()),
timeZone: Localization.timezone,
location: itemEventData.lib_agence + " " + itemEventData.adresse_agence + " - " + itemEventData.ville_agence + " " + itemEventData.cp_agence
}
}
let eventCreated = await Calendar.getEventsAsync([currCalendarId], startDate, endDate).catch((error) => console.log("ERROR get EVENT >>> " + JSON.stringify(error)));
let eventFinded = eventCreated.filter(eventInCalendar => eventInCalendar.title === itemEventData.titre_flyer + " - " + itemEventData.ville_agence);
if (eventFinded.length) {
//console.log('event already created ');
this.setState({ eventSavedInCalendar: true });
} else {
//console.log('no event ')
}
if (!this.state.eventSavedInCalendar) {
var idEvent = await Calendar.createEventAsync(currCalendarId, detailsEvent).catch((error) => console.log("ERROR create EVENT >>> " + JSON.stringify(error)));
// console.log('event created : OK');
console.log('event created : id = ' + JSON.stringify(idEvent));
this.setState({ eventSavedInCalendar: true });
await Calendar.updateEventAsync(idEvent, {
alarms: [{ relativeOffset: -60 * 24, method: Calendar.AlarmMethod.ALERT }, { relativeOffset: -60, method: Calendar.AlarmMethod.ALERT }],
timeZone: Localization.timezone
}).catch((error) => console.log("ERROR update Event >>> " + JSON.stringify(error)));
}
}
}
这是我的createCalendar函数:
async createCalendar() {
const defaultCalendarSource =
Platform.OS === 'ios'
? await this.getDefaultCalendarSource()
: { isLocalAccount: true, name: CONFIG_APP.APP_ENSEIGNE };
if (Platform.OS === 'ios') {
const newCalendarID = await Calendar.createCalendarAsync({
title: CONFIG_APP.APP_ENSEIGNE,
color: APP_COLORS.HomeActiveColor,
entityType: Calendar.EntityTypes.EVENT,
sourceId: defaultCalendarSource.source.id,
source: defaultCalendarSource.source,
name: CONFIG_APP.APP_ENSEIGNE,
ownerAccount: 'personal',
accessLevel: Calendar.CalendarAccessLevel.OWNER,
});
} else {
const newCalendarID = await Calendar.createCalendarAsync({
title: CONFIG_APP.APP_ENSEIGNE,
color: APP_COLORS.HomeActiveColor,
entityType: Calendar.EntityTypes.EVENT,
sourceId: defaultCalendarSource.id,
source: defaultCalendarSource,
name: CONFIG_APP.APP_ENSEIGNE,
ownerAccount: 'personal',
accessLevel: Calendar.CalendarAccessLevel.OWNER,
isSynced: true
});
}
// console.log(`Your new calendar ID is: ${newCalendarID}`);
return newCalendarID;
}
我正在努力
有什么主意吗? 谢谢