Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.

Add support for iOS17+ Calendar Permissions #2109

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Samples/Samples.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>10.0</string>
<string>11.0</string>
<key>CFBundleDisplayName</key>
<string>Xamarin.Essentials</string>
<key>CFBundleIdentifier</key>
Expand Down Expand Up @@ -78,5 +78,11 @@
<array>
<string>mailto</string>
</array>
<key>NSCalendarsFullAccessUsageDescription</key>
<string>Full access to the Calendar</string>
<key>NSCalendarsWriteOnlyAccessUsageDescription</key>
<string>Write only access to the Calendar</string>
<key>NSRemindersFullAccessUsageDescription</key>
<string>Full access to reminders</string>
</dict>
</plist>
62 changes: 55 additions & 7 deletions Xamarin.Essentials/Permissions/Permissions.ios.watchos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,40 @@ internal static async Task<PermissionStatus> RequestPermissionAsync(EKEntityType
{
var eventStore = new EKEventStore();

var results = await eventStore.RequestAccessAsync(entityType);
Tuple<bool, NSError> results = null;

if (Platform.HasOSVersion(17, 0))
{
if (entityType == EKEntityType.Reminder)
results = await eventStore.RequestFullAccessToRemindersAsync();
if (entityType == EKEntityType.Event)
results = await eventStore.RequestFullAccessToEventsAsync();
}
else
{
results = await eventStore.RequestAccessAsync(entityType);
}

return results.Item1 ? PermissionStatus.Granted : PermissionStatus.Denied;
}
}

public partial class CalendarRead : BasePlatformPermission
{
protected override Func<IEnumerable<string>> RequiredInfoPlistKeys =>
() => new string[] { "NSCalendarsUsageDescription" };
protected override Func<IEnumerable<string>> RequiredInfoPlistKeys
{
get
{
if (Platform.HasOSVersion(17, 0))
{
return () => new string[] { "NSCalendarsFullAccessUsageDescription" };
}
else
{
return () => new string[] { "NSCalendarsUsageDescription" };
}
}
}

public override Task<PermissionStatus> CheckStatusAsync()
{
Expand All @@ -60,8 +84,20 @@ public override Task<PermissionStatus> RequestAsync()

public partial class CalendarWrite : BasePlatformPermission
{
protected override Func<IEnumerable<string>> RequiredInfoPlistKeys =>
() => new string[] { "NSCalendarsUsageDescription" };
protected override Func<IEnumerable<string>> RequiredInfoPlistKeys
{
get
{
if (Platform.HasOSVersion(17, 0))
{
return () => new string[] { "NSCalendarsWriteOnlyAccessUsageDescription" };
}
else
{
return () => new string[] { "NSCalendarsUsageDescription" };
}
}
}

public override Task<PermissionStatus> CheckStatusAsync()
{
Expand All @@ -84,8 +120,20 @@ public override Task<PermissionStatus> RequestAsync()

public partial class Reminders : BasePlatformPermission
{
protected override Func<IEnumerable<string>> RequiredInfoPlistKeys =>
() => new string[] { "NSRemindersUsageDescription" };
protected override Func<IEnumerable<string>> RequiredInfoPlistKeys
{
get
{
if (Platform.HasOSVersion(17, 0))
{
return () => new string[] { "NSRemindersFullAccessUsageDescription" };
}
else
{
return () => new string[] { "NSRemindersUsageDescription" };
}
}
}

public override Task<PermissionStatus> CheckStatusAsync()
{
Expand Down
8 changes: 5 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pr:
- develop

variables:
BASE_VERSION: 1.8.0
BASE_VERSION: 1.8.1
PREVIEW_LABEL: 'ci'
BUILD_NUMBER: $[counter(format('{0}_{1}_{2}', variables['BASE_VERSION'], variables['PREVIEW_LABEL'], variables['Build.SourceBranch']), 1)]
NUGET_VERSION: $[format('{0}-{1}.{2}', variables['BASE_VERSION'], variables['PREVIEW_LABEL'], variables['BUILD_NUMBER'])]
Expand Down Expand Up @@ -47,6 +47,8 @@ stages:
windowsImageOverride: AzurePipelinesWindows2019compliant
${{ if ne(variables['System.TeamProject'], 'devdiv') }}:
windowsImage: windows-2019
macosImage: 'macos-13'
xcode: '15.0.1'
areaPath: 'DevDiv\Xamarin SDK'
masterBranchName: 'main'
${{ if startsWith(variables['Build.SourceBranch'], 'refs/tags/') }}: #we are shipping our product
Expand Down Expand Up @@ -141,7 +143,7 @@ stages:

- template: .ci/build.v1.yml@components
parameters:
macosImage: 'macos-12'
macosImage: 'macos-13'
name: devicetests_ios
runChecks: false
displayName: iOS
Expand All @@ -152,7 +154,7 @@ stages:
cakeFile: DeviceTests/build.cake
cakeTarget: test-ios-emu
cake: $(CAKE_VERSION)
xcode: '14.2'
xcode: '15.0.1'
xharness: '1.0.0-prerelease.23212.1'

- template: .ci/build.v1.yml@components
Expand Down