gpt4 book ai didi

ios - 权限添加日历事件iOS

转载 作者:行者123 更新时间:2023-12-01 17:19:37 24 4
gpt4 key购买 nike

没有权限时如何显示错误? (例如,“您没有允许我们在日历中写信的权限。”)。

这是我的代码:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {

EKEventStore *es = [[EKEventStore alloc] init];
[es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
/* This code will run when uses has made his/her choice */
}];
}
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyy"];

NSString *fechainicio = datum;
NSString *fechafin = datum;
titel = [NSString stringWithFormat:@"%@ (%@)", titel, plaatslabel.text];

NSDate * date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:fechainicio];
NSDate * date2 = [[NSDate alloc] init];
date2 = [dateFormatter dateFromString:fechafin];

EKEventStore *eventStore = [[EKEventStore alloc] init];

EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"Optreden Ronald Goedemondt";
event.location = titel;
event.allDay = YES;

event.startDate = date;
event.endDate = date2;

[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];

WBSuccessNoticeView *notice = [WBSuccessNoticeView successNoticeInView:self.view title:@"Show geplaatst in uw agenda."];
[notice show];

最佳答案

如果已授予访问权限,则granted将为YES,否则为NO
另外,您应确保仅在必要时才调用-requestAccessToEntityType:completion::

EKEventStore *es = [[EKEventStore alloc] init];
EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
BOOL needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined);

if (needsToRequestAccessToEventStore) {
[es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
// Access granted
} else {
// Denied
}
}];
} else {
BOOL granted = (authorizationStatus == EKAuthorizationStatusAuthorized);
if (granted) {
// Access granted
} else {
// Denied
}
}

关于ios - 权限添加日历事件iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14687991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com