blob: 79a85ef3d2d6b8f836c1da3b9b23605de447a75a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdarwinpermissionplugin_p_p.h"
#include <EventKit/EventKit.h>
QT_DEFINE_PERMISSION_STATUS_CONVERTER(EKAuthorizationStatus);
@interface QDarwinCalendarPermissionHandler ()
@property (nonatomic, retain) EKEventStore *eventStore;
@end
@implementation QDarwinCalendarPermissionHandler
- (Qt::PermissionStatus)checkPermission:(QPermission)permission
{
Q_UNUSED(permission);
return [self currentStatus];
}
- (Qt::PermissionStatus)currentStatus
{
const auto status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
return nativeStatusToQtStatus(status);
}
- (QStringList)usageDescriptionsFor:(QPermission)permission
{
Q_UNUSED(permission);
return { "NSCalendarsUsageDescription" };
}
- (void)requestPermission:(QPermission)permission withCallback:(PermissionCallback)callback
{
if (!self.eventStore) {
// Note: Creating the EKEventStore results in warnings in the
// console about "An error occurred in the persistent store".
// This seems like a EventKit API bug.
self.eventStore = [[EKEventStore new] autorelease];
}
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError * _Nullable error) {
Q_UNUSED(granted); // We use status instead
// Permission denied will result in an error, which we don't
// want to report/log, so we ignore the error and just report
// the status.
Q_UNUSED(error);
callback([self currentStatus]);
}
];
}
@end
#include "moc_qdarwinpermissionplugin_p_p.cpp"
|