builttoroam / device_calendar

A cross platform plugin for modifying calendars on the user's device
https://pub.dev/packages/device_calendar
BSD 3-Clause "New" or "Revised" License
259 stars 258 forks source link

ios flutter: PlatformException(401, The user has not allowed this application to modify their calendar(s), null, null) #485

Closed FangPro closed 1 year ago

FangPro commented 1 year ago

I ran my program on the iOS simulator, but this error occurred

flutter: PlatformException(401, The user has not allowed this application to modify their calendar(s), null, null)

This is my code: `void createAlarmCalendar({required ScheduleModel model}) async{ var hasPermissions = await DeviceCalendarPlugin().hasPermissions(); if(hasPermissions.isSuccess){ _createEvent(model: model); } else { await DeviceCalendarPlugin().requestPermissions().then((result){ if(result.isSuccess){ _createEvent(model: model); } }); } }

_createEvent({required ScheduleModel model}) async{ await DeviceCalendarPlugin().createOrUpdateEvent(Event( calenderId, eventId: model.id!, title: "${model.course!}直播课", start: TZDateTime.fromMillisecondsSinceEpoch(tz.local, model.liveStart!), end: TZDateTime.fromMillisecondsSinceEpoch(tz.local, model.liveEnd!), availability: Availability.Free, attendees: [], allDay: false, status: EventStatus.Tentative, location: tz.local.name, reminders: [], )).then((result){ if(result!.data!=null&&result.data!=""){ debugPrint(result.data!); isCalendars = true; StorageManage.sp!.setString(model.id!, result.data!); bus.emit("REFRESH_CALENDAR"); ToastUtil.showText("当前直播提醒已开启"); notifyListeners(); } else { ToastUtil.showText("当前直播提醒开启失败"); } }); }`

IVLIVS-III commented 1 year ago

@FangPro have you checked that the calendar you are trying to modify is not readonly?

FangPro commented 1 year ago

This is the calendar on the iOS simulator. What additional information do I need to provide

IVLIVS-III commented 1 year ago

well, when calling retrieveCalendars, how many calendars are returned?

IVLIVS-III commented 1 year ago

Did you follow the steps to integrate iOS?

FangPro commented 1 year ago

Step configuration for integrating iOS: `NSCalendarsUsageDescription

Access most functions for calendar viewing and editing. NSContactsUsageDescription Access contacts for event attendee editing.` Do I need any additional configurations?
FangPro commented 1 year ago

Hello author, it's my problem. I have summarized the following reasons:

  1. Before creating an event on iOS, it is necessary to directly request permissions, rather than first determining whether permissions exist
  2. Before creating an event, you need to traverse and query the calendar to obtain a specified calendar ID
  3. In the creation event method parameters, do not specify the event ID yourself. The callback method for creating the event will help us return The above is what I have found to be worth noting. Thank you to the plugin author.
mbcHans commented 2 months ago

Hello author, it's my problem. I have summarized the following reasons:

  1. Before creating an event on iOS, it is necessary to directly request permissions, rather than first determining whether permissions exist
  2. Before creating an event, you need to traverse and query the calendar to obtain a specified calendar ID
  3. In the creation event method parameters, do not specify the event ID yourself. The callback method for creating the event will help us return The above is what I have found to be worth noting. Thank you to the plugin author.

Hi, how did you solve this issue? I meet this problem too.

FangPro commented 2 months ago

Have you encountered the same error message? On which platform, Android or iOS?

------------------ 原始邮件 ------------------ 发件人: "builttoroam/device_calendar" @.>; 发送时间: 2024年4月17日(星期三) 下午5:16 @.>; 抄送: "Billows Bear @.>;"State @.>; 主题: Re: [builttoroam/device_calendar] ios flutter: PlatformException(401, The user has not allowed this application to modify their calendar(s), null, null) (Issue #485)

Hello author, it's my problem. I have summarized the following reasons:

Before creating an event on iOS, it is necessary to directly request permissions, rather than first determining whether permissions exist

Before creating an event, you need to traverse and query the calendar to obtain a specified calendar ID

In the creation event method parameters, do not specify the event ID yourself. The callback method for creating the event will help us return The above is what I have found to be worth noting. Thank you to the plugin author.

Hi, how did you solve this issue? I meet this problem too.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>

mbcHans commented 2 months ago

Hello author, it's my problem. I have summarized the following reasons: Before creating an event on iOS, it is necessary to directly request permissions, rather than first determining whether permissions exist Before creating an event, you need to traverse and query the calendar to obtain a specified calendar ID In the creation event method parameters, do not specify the event ID yourself. The callback method for creating the event will help us return The above is what I have found to be worth noting. Thank you to the plugin author. Hi, how did you solve this issue? I meet this problem too.

Yes, same error log happened on iOS platform.

FangPro commented 2 months ago

Have you applied for permission before creating a subscription event,Then you can take a look at my code below:

_createEvent({required ScheduleModel model}) async{     var currentLocation = getLocation(await FlutterNativeTimezone.getLocalTimezone());     setLocalLocation(currentLocation);     await DeviceCalendarPlugin().retrieveCalendars().then((list) async{       if(list.data!.isNotEmpty){         for(var v in list.data!){           debugPrint("name===>${v.name!}");           debugPrint("id===>${v.id!}");           debugPrint("accountName===>${v.accountName!}");           debugPrint("accountType===>${v.accountType!}");           debugPrint("isReadOnly===>${v.isReadOnly!}");           debugPrint("isDefault===>${v.isDefault!}");           if(v.isDefault! && !v.isReadOnly!){             calenderId = v.id!;           } else if(v.accountType == "LOCAL"){             calenderId = v.id!;           }         }       }       debugPrint("calenderId-------------->$calenderId");       await DeviceCalendarPlugin().createOrUpdateEvent(Event(         calenderId,         title: "${model.course!}直播课",         start: TZDateTime.fromMillisecondsSinceEpoch(currentLocation, model.liveStart!),         end: TZDateTime.fromMillisecondsSinceEpoch(currentLocation, model.liveEnd!),         availability: Availability.Free,         attendees: [],         allDay: false,         status: EventStatus.Confirmed,         location: currentLocation.name,         reminders: [           Reminder(minutes: 60),           Reminder(minutes: 30),           Reminder(minutes: 10),           Reminder(minutes: 5),         ],       )).then((result){         if(result!.data!=null && result.data !=""){           debugPrint(result.data);           isCalendars = true;           StorageManage.sp!.setString(model.id!, result.data!);           bus.emit("REFRESH_CALENDAR");           ToastUtil.showText("当前直播提醒已开启");           notifyListeners();         } else {           ToastUtil.showText("当前直播提醒开启失败");         }       });     });   }

------------------ 原始邮件 ------------------ 发件人: "builttoroam/device_calendar" @.>; 发送时间: 2024年4月18日(星期四) 上午9:34 @.>; 抄送: "Billows Bear @.>;"State @.>; 主题: Re: [builttoroam/device_calendar] ios flutter: PlatformException(401, The user has not allowed this application to modify their calendar(s), null, null) (Issue #485)

Hello author, it's my problem. I have summarized the following reasons: Before creating an event on iOS, it is necessary to directly request permissions, rather than first determining whether permissions exist Before creating an event, you need to traverse and query the calendar to obtain a specified calendar ID In the creation event method parameters, do not specify the event ID yourself. The callback method for creating the event will help us return The above is what I have found to be worth noting. Thank you to the plugin author. Hi, how did you solve this issue? I meet this problem too.

Yes, same error log happened on iOS platform.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>