admin管理员组文章数量:1122832
Has anyone encountered an issue in their MAUI program where opening the app settings works on earlier iOS versions but fails on iOS 18?
UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString));
I am receiving an error message below:
**"BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to migrate to the non-deprecated UIApplication.open(_:options:completionHandler:). Force returning false (NO)."**
Has anyone encountered an issue in their MAUI program where opening the app settings works on earlier iOS versions but fails on iOS 18?
UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString));
I am receiving an error message below:
**"BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to migrate to the non-deprecated UIApplication.open(_:options:completionHandler:). Force returning false (NO)."**
3 Answers
Reset to default 2The issue occurs because Apple has deprecated UIApplication.SharedApplication.OpenUrl in favor of the newer UIApplication.Open API, a change that began with iOS 10 and is enforced more strictly in iOS 18. The error message indicates that your code must be updated to utilize this modern API.
Updated Code
To resolve this, replace your UIApplication.SharedApplication.OpenUrl call with the UIApplication.SharedApplication.Open method, ensuring you use the appropriate options and completion handler. Here’s how you can implement the fix:
var url = new NSUrl(UIApplication.OpenSettingsUrlString);
if (UIApplication.SharedApplication.CanOpenUrl(url))
{
UIApplication.SharedApplication.OpenUrl(url, new UIApplicationOpenUrlOptions(), (success) =>
{
if (!success)
{
Console.WriteLine("Failed to open app settings.");
}
});
}
else
{
Console.WriteLine("Cannot open app settings URL.");
}
try
{
var url = new NSUrl(UIApplication.OpenSettingsUrlString);
if (UIApplication.SharedApplication.CanOpenUrl(url))
{
var success = await UIApplication.SharedApplication.OpenUrlAsync(url, new UIApplicationOpenUrlOptions());
if (!success)
{
Console.WriteLine("Failed to open app settings.");
}
}
else
{
Console.WriteLine("Cannot open app settings URL.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
First of all, the UIApplication.SharedApplication.OpenUrl(NSUrl url)
was deprecated. But the OpenUrl(NSUrl url, NSDictionary options, [BlockProxy(typeof(NIDActionArity1V4))] Action<bool>? completion)
is still supported. And Sanjay Hans used this method.
In addition, Maui has added OpenUrlAsync(NSUrl url, UIApplicationOpenUrlOptions options)
api. You can use it:
await UIApplication.SharedApplication
.OpenUrlAsync(new NSUrl(UIApplication.OpenSettingsUrlString),
new UIApplicationOpenUrlOptions());
本文标签: cUnable to open app settings in iOS 18 MAUIStack Overflow
版权声明:本文标题:c# - Unable to open app settings in iOS 18 MAUI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309068a1933885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论