diff --git a/src/PostIt/Directory.Packages.props b/src/PostIt/Directory.Packages.props index 900f1428..62b3a343 100644 --- a/src/PostIt/Directory.Packages.props +++ b/src/PostIt/Directory.Packages.props @@ -14,6 +14,7 @@ + diff --git a/src/PostIt/PostIt/PostIt.csproj b/src/PostIt/PostIt/PostIt.csproj index d9cf96d3..1b14653a 100644 --- a/src/PostIt/PostIt/PostIt.csproj +++ b/src/PostIt/PostIt/PostIt.csproj @@ -3,11 +3,13 @@ net10.0 enable latest + true true 1.0.1.0 1.0.1.0 1.0.1-5+Branch.main.Sha.0617fc6bda7151c70559d87177e2dcfb1b60995f 1.0.1-5 + @@ -24,6 +26,7 @@ + @@ -39,4 +42,4 @@ - \ No newline at end of file + diff --git a/src/PostIt/PostIt/Services/ContactService.cs b/src/PostIt/PostIt/Services/ContactService.cs new file mode 100644 index 00000000..bc71d11b --- /dev/null +++ b/src/PostIt/PostIt/Services/ContactService.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel.Communication; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices; + +public class ContactService +{ + public async Task> GetDeviceContactsAsync() + { + // 1. Ensure the platform supports MAUI Essentials APIs + if (DeviceInfo.Current.Platform == DevicePlatform.Unknown) + { + throw new PlatformNotSupportedException("MAUI Essentials is not available on this platform."); + } + + try + { + // 2. Request runtime permission (Required for Android & iOS) + var status = await Permissions.RequestAsync(); + if (status != PermissionStatus.Granted) + { + // Permission denied by user + return Array.Empty(); + } + + // 3. Fetch all contacts + var contactsEnumerable = await Contacts.Default.GetAllAsync(); + return contactsEnumerable ?? Array.Empty(); + } + catch (Exception ex) + { + // Handle cross-platform exceptions or logs here + System.Diagnostics.Debug.WriteLine($"Error fetching contacts: {ex.Message}"); + return Array.Empty(); + } + } +}