Apizr
Apizr copied to clipboard
Spontaneous Crash on iOS with DelegatingHandler
Hi,
we are getting spontaneous crashes on iOS if we are using our custom DelegatingHandler. Sometimes the app is working for couple of minutes/api calls without crash and then it crashes. There is not relevant exception for this, just a SIGABRT Crash from iOS. If we hard-code our api key in the delegatinghandler, the app is working fine. Is there some misconfiguration on our side? Or is there better way to do this? Thanks.
Versions: Maui: 8.0.40 (happens in every Maui 8> version) Apizr: 5.4.0 Shiny.Framework: 4.1.0 Prism.DryIoc.Maui: 9.0.401-pre
Registration in Maui:
builder.Services.AddApizr(apizrRegistry => apizrRegistry .AddManagerFor<IImpressumApi>() apizrExtendedCommonOptionsBuilder => apizrExtendedCommonOptionsBuilder .WithBaseAddress(builder.Configuration.GetValue<Uri>("BaseUrl")) .AddDelegatingHandler((provider) => new XApiKeyAuthenticationHandler(provider.GetRequiredService<ISecureStorage>())) .WithAkavacheCacheHandler() .WithExCatching(OnException, letThrowOnExceptionWithEmptyCache: false) .WithLogging( #if DEBUG HttpTracerMode.Everything, HttpMessageParts.All, LogLevel.Trace, LogLevel.Information, LogLevel.Critical #else HttpTracerMode.ExceptionsOnly, HttpMessageParts.ResponseAll, Microsoft.Extensions.Logging.LogLevel.Trace, Microsoft.Extensions.Logging.LogLevel.Information, Microsoft.Extensions.Logging.LogLevel.Critical #endif ) .WithConnectivityHandler<IConnectivity>(connectivity => connectivity.NetworkAccess == NetworkAccess.Internet));
DelegatingHandler:
`public class XApiKeyAuthenticationHandler : DelegatingHandler { public XApiKeyAuthenticationHandler(ISecureStorage secureStorage) : this(secureStorage, new HttpClientHandler()) { }
public XApiKeyAuthenticationHandler(ISecureStorage secureStorage, HttpMessageHandler innerHandler) : base(innerHandler)
{
SecureStorage = secureStorage;
}
protected ISecureStorage SecureStorage { get; }
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
var identityKey = await SecureStorage.GetAsync(AppConstants.IdentityKey);
if (!string.IsNullOrWhiteSpace(identityKey))
{
request.Headers.Add("X-Identity-Key", identityKey);
}
return await base.SendAsync(request, cancellationToken);
}
}`