在方法1的回调函数里granted一直是undefind,请问是不是native.js代码的问题还是别的问题呢
function addIosEvent() {
var EventKit = plus.ios.importClass('EventKit');
var EKEventStore = plus.ios.importClass("EKEventStore");
var eventDB = new EKEventStore();
var granted = plus.ios.newObject("BOOL");
// mui.alert(JSON.stringify(granted));
var error = plus.ios.newObject("NSError");
eventDB.requestAccessToEntityTypecompletion(0, function(granted, error) { //方法1
console.log('209' + granted);
console.log('210' + error);
if(error) {
console.log('211');
// display error message here
} else if(!granted) {
//被用户拒绝,不允许访问日历
console.log('216');
// display access denied error message here
} else {
//创建事件
var EKEvent = plus.ios.import("EKEvent");
var event = EKEvent.eventWithEventStore(eventDB);
event.title = "测试写入日历事件";
event.location = "北京海淀";
//06.07 时间格式
var dateFormatter = plus.ios.newObject("NSDateFormatter");
plus.ios.invoke(dateFormatter, "setAMSymbol:", "AM");
plus.ios.invoke(dateFormatter, "setPMSymbol:", "PM");
plus.ios.invoke(dateFormatter, "setDateFormat:", "yyyy/MM/dd hh:mmaaa");
var date = plus.ios.newObject("NSDate");
var s = plus.ios.invoke(dateFormatter, "stringFromDate:", date);
console.log("----" + s);
//开始时间(必须传)
event.startDate = plus.ios.invoke(date, "dateByAddingTimeInterval:", 60 * 2);
//结束时间(必须传)
event.endDate = plus.ios.invoke(date, "dateByAddingTimeInterval:", 60 * 5 * 24);
//添加提醒
//第一次提醒 (几分钟后)
plus.ios.invoke(event, "addAlarm:", plus.ios.invoke("EKAlarm", "alarmWithRelativeOffset:", 60.0 * 1.0));
//第二次提醒 ()
//[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -10.0f * 24]];
//06.07 add 事件类容备注
var str = plus.ios.newObject("NSString", "eventWithEventStore:", eventDB);
event.notes = plus.ios.newObject("NSString", "stringWithFormat:", "%@", "接受信息类容备注");
plus.ios.invoke(event, "setCalendar:", plus.ios.invoke(eventDB, "defaultCalendarForNewEvents:"));
var err = plus.ios.newObject("NSError");
plus.ios.invoke(eventDB, "saveEvent:span:error:", event, "EKSpanThisEvent", err);
console.log("保存成功");
}
});
}
1 个回复
zh666 (作者) - 90后it男
@DCloud 请问此bug是在下一版里更新,还是暂时没有解决呀?