zhaoyu2020
zhaoyu2020
  • 发布:2023-07-10 15:47
  • 更新:2023-11-02 17:44
  • 阅读:156

ios 调用 requestAccessToEntityTypecompletion 闪退

分类:Native.js

ios 调用 requestAccessToEntityTypecompletion 闪退

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("保存成功");    

            }    
        });    
}  
2023-07-10 15:47 负责人:无 分享
已邀请:
追影和糖糖

要回复问题请先登录注册