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)."**

Share Improve this question edited Nov 22, 2024 at 9:07 Sanjay 4901 gold badge8 silver badges16 bronze badges asked Nov 21, 2024 at 16:08 error404error404 237 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

The 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