Skip to content

Commit

Permalink
Use some of the new iOS APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Sep 5, 2024
1 parent 9522861 commit 660a4e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Core/src/Platform/iOS/LabelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ internal static void UpdateTextHtml(this UILabel platformLabel, ILabel label)
var attr = new NSAttributedStringDocumentAttributes
{
DocumentType = NSDocumentType.HTML,
#if NET8_0_OR_GREATER
CharacterEncoding = NSStringEncoding.UTF8
#else
StringEncoding = NSStringEncoding.UTF8
#endif
};

NSError nsError = new();
Expand Down
25 changes: 23 additions & 2 deletions src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UIKit;

namespace Microsoft.Maui.Devices
Expand All @@ -21,15 +22,35 @@ public void Perform(HapticFeedbackType type)

void Click()
{
var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light);
UIImpactFeedbackGenerator impact;
#if NET8_0_OR_GREATER
if (OperatingSystem.IsIOSVersionAtLeast(17, 4) || OperatingSystem.IsMacCatalystVersionAtLeast(17, 4))
{
impact = UIImpactFeedbackGenerator.GetFeedbackGenerator(UIImpactFeedbackStyle.Light, new UIView());
}
else
#endif
{
impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light);
}
impact.Prepare();
impact.ImpactOccurred();
impact.Dispose();
}

void LongPress()
{
var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium);
UIImpactFeedbackGenerator impact;
#if NET8_0_OR_GREATER
if (OperatingSystem.IsIOSVersionAtLeast(17, 4) || OperatingSystem.IsMacCatalystVersionAtLeast(17, 4))
{
impact = UIImpactFeedbackGenerator.GetFeedbackGenerator(UIImpactFeedbackStyle.Medium, new UIView());
}
else
#endif
{
impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium);
}
impact.Prepare();
impact.ImpactOccurred();
impact.Dispose();
Expand Down
15 changes: 14 additions & 1 deletion src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,22 @@ void AuthSessionCallback(NSUrl cbUrl, NSError error)
sf = null;
}


if (OperatingSystem.IsIOSVersionAtLeast(12))
{
was = new ASWebAuthenticationSession(WebUtils.GetNativeUrl(url), scheme, AuthSessionCallback);
#if NET8_0_OR_GREATER
if (OperatingSystem.IsIOSVersionAtLeast(17, 4) || OperatingSystem.IsMacCatalystVersionAtLeast(17, 4))
{
// Use the new ASWebAuthenticationSession constructor with ASWebAuthenticationSessionCallback overload
var callback = ASWebAuthenticationSessionCallback.Create(scheme);
was = new ASWebAuthenticationSession(WebUtils.GetNativeUrl(url), callback, AuthSessionCallback);
}
else
#endif
{
// Fallback to the original ASWebAuthenticationSession constructor for iOS versions below 17.4
was = new ASWebAuthenticationSession(WebUtils.GetNativeUrl(url), scheme, AuthSessionCallback);
}

if (OperatingSystem.IsIOSVersionAtLeast(13))
{
Expand Down

0 comments on commit 660a4e6

Please sign in to comment.