console.log('ios Start.');
var myDate = new Date();
var day = myDate.getDate();
var month = myDate.getMonth() + 1;
var year = myDate.getFullYear();
var StartDate = year + "-" + month + "-" + day + " 00:00:00";
year = myDate.getFullYear() + 1;
var endDate = year + "-" + month + "-" + day + " 00:00:00";
document.write(StartDate);
document.write("<br/>");
document.write(endDate);
document.write("<br/>");
var dateFormatter = plus.ios.newObject("NSDateFormatter");
plus.ios.invoke(dateFormatter, "setDateFormat:", "yyyy-MM-dd hh:mm:ss");
var sDate = plus.ios.invoke(dateFormatter, "dateFromString:", StartDate);
var eDate = plus.ios.invoke(dateFormatter, 'dateFromString:', endDate);
var EKEventStore = plus.ios.importClass("EKEventStore");
var Estore = new EKEventStore();
var granted = plus.ios.newObject("BOOL");
var NSError = plus.ios.newObject("NSError");
Estore.requestAccessToEntityTypecompletion(0,function(granted,NSError){
var store = plus.ios.newObject("EKEventStore");
// 问: 下面这个段 为什么不能用 Estore 而是 必须用 store
// Estore = new EKEventStore() 和 store = plus.ios.newObject("EKEventStore");
// 两者的区别 在那点? 如果下面这句 应该怎么改才能使用 Estore
var predicate = plus.ios.invoke(store,"predicateForEventsWithStartDate:endDate:calendars:"
,sDate,eDate,null);
var eventsMatching = plus.ios.invoke(store,"eventsMatchingPredicate:",predicate);
document.write("<br/>");
var count = eventsMatching.plusGetAttribute("count");
document.write("日历数量:" + count + "<br/>");
var events;
var title;
var D;
var calendar ;
for (var i=0; i<count; i++) {
events = plus.ios.invoke(eventsMatching,"objectAtIndex:",i);
title = events.plusGetAttribute("title");
document.write("标题:" + title + "<br/>");
// 在日历数组里面还有 calendar 不知道这个怎么处理
calendar = events.plusGetAttribute("calendar");
sDate = events.plusGetAttribute("startDate");
D = plus.ios.invoke(dateFormatter, "stringFromDate:", sDate);
document.write("开始时间:" + D + "<br/>");
eDate = events.plusGetAttribute("endDate");
D = plus.ios.invoke(dateFormatter, "stringFromDate:", eDate)
document.write("结束时间:" + D + "<br/>");
}
document.write("---END---");
});
plus.ios.deleteObject(Estore);
plus.ios.deleteObject(granted);
plus.ios.deleteObject(NSError);
// 在这要是加入 plus.ios.deleteObject(dateFormatter); 所有显示的时间就会 是 null 了
// Estore.requestAccessToEntityTypecompletion 的流程内 dateFormatter 对象已经被删除
// 这好像是个 异步 要怎么才能 等待 异步结束?? 再继续后面执行
console.log('ios end.');
0 个回复