Skip to content

Commit

Permalink
fix attributed string crash (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
sleushunou authored Oct 8, 2024
1 parent ff8e2b7 commit 5746ee4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,29 @@ public static NSMutableAttributedString BuildAttributedStringFromHtml(

try
{
NSAttributedString? attributedString;

if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0))
{
if (string.IsNullOrEmpty(html))
{
attributedString = new NSAttributedString();
}
else
{
var markdown = new Html2Markdown.Converter().Convert(html);
#pragma warning disable CS8601 // Possible null reference assignment.
var attributedString = new NSAttributedString(html, importParams, ref error);
attributedString = new NSAttributedString(markdown, default, default, out error);
#pragma warning restore CS8601 // Possible null reference assignment.
}
}
else
{
#pragma warning disable CS8601 // Possible null reference assignment.
attributedString = new NSAttributedString(html, importParams, ref error);
#pragma warning restore CS8601 // Possible null reference assignment.
}

return new NSMutableAttributedString(attributedString);
}
catch (Exception ex)
Expand Down
4 changes: 4 additions & 0 deletions Softeq.XToolkit.Common.iOS/Softeq.XToolkit.Common.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
<ProjectReference Include="..\Softeq.XToolkit.Common\Softeq.XToolkit.Common.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Html2Markdown" Version="7.0.1.9" />
</ItemGroup>

</Project>

0 comments on commit 5746ee4

Please sign in to comment.