zh666
zh666
  • 发布:2017-07-19 17:18
  • 更新:2021-09-02 16:41
  • 阅读:1737

利用Native.js向日历插入提醒事件,但是权限一直获取为undefined,但是app已经获得日历权限,大神可以帮着解决一下吗?可以有偿。谢谢

分类:Native.js

function saveE() {
var EventKit = plus.ios.importClass('EventKit');
var EKEventStore = plus.ios.importClass("EKEventStore");
var eventDB = new EKEventStore();
var granted = plus.ios.newObject("BOOL");
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("保存成功");  

        }  
    });  

}

2017-07-19 17:18 负责人:无 分享
已邀请:
l***@chinaunicom.cn

l***@chinaunicom.cn

请问这个有解决了吗

该问题目前已经被锁定, 无法添加新回复