leah_huang
leah_huang
  • 发布:2016-11-30 10:59
  • 更新:2018-05-29 09:57
  • 阅读:4897

利用Native.js向日历插入提醒事件,但是权限一直获取为undefined,但是app已经获得日历权限,这是什么原因

分类:Native.js
[eventDB requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {  
..................  
}];

上面是OC代码
下面是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("保存成功");  
  
			}  
		});  
}  

granted获取的值一直是undefined,这是什么原因呢

2016-11-30 10:59 负责人:无 分享
已邀请:
leah_huang

leah_huang (作者)

@DCloud_heavensoft @DCloud_IOS_XTY 已经使用var EKstatus = EKEventStore.authorizationStatusForEntityType();
获得日历权限为3(EKAuthorizationStatusAuthorized),但是日历提醒还是添加不进去,这是怎么回事呢

leah_huang

leah_huang (作者)

@DCloud_heavensoft @DCloud_IOS_XTY @DCloud_客服_小青年 请问此bug是在下一版里更新,还是暂时没有解决呀?

gmmx133

gmmx133

楼主解决了吗? 有什么替代方法吗

  • leah_huang (作者)

    这个问题是因为没法获取block的参数列表造成的 暂时没有找到解决方案


    2016-12-23 11:33

  • 7***@qq.com

    回复 leah_huang: 这个有解决了吗


    2019-12-02 15:45

Thyme释念帅

Thyme释念帅

eventDB.requestAccessToEntityTypecompletion(0,function(granted,error){
console.log('209'+granted);
console.log('210'+error);
}
现在的版本好像回调函数都不调用了,没法在控制台打印granted和error

  • 低调的帅气

    没有回调的方法,就不能和原生交互了,兄弟,可找到合适的方式处理了?


    2017-04-06 13:13

低调的帅气

低调的帅气

楼主解决了吗?求告知答案

wenju

wenju - https://www.mescroll.com -- 精致的下拉刷新和上拉加载组件

解决了吗 大神们~

  • 猫猫猫猫

    没有,由于存在这个bug,导致后来用的离线插件解决的。


    2017-08-25 09:05

  • wenju

    回复 猫猫猫猫:好的 O(∩_∩)O谢谢大神~


    2017-08-25 11:04

崔尐磊

崔尐磊

楼主解决了吗 求告知

y***@live.cn

y***@live.cn

@DCloud_heavensoft @DCloud_IOS_XTY 什么版本能解决这个bug

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