You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于.NET MAUI的跨平台应用:如何检测iOS设备上是否安装Microsoft Word

Checking if Microsoft Word is Installed on iOS in .NET MAUI

Hey there! I've tackled this exact problem in a .NET MAUI cross-platform app before, so let me break down the reliable way to detect Microsoft Word on iOS.

On iOS, app detection works by checking if the target app's custom URL scheme can be opened. Microsoft Word uses the ms-word:// scheme, so we can leverage that along with .NET MAUI's Launcher API to verify installation.

Step 1: Update Info.plist (Critical!)

First, you need to declare the ms-word scheme in your iOS project's Info.plist file. iOS blocks queries to unlisted schemes by default, so this step is non-negotiable.

Open Platforms/iOS/Info.plist and add the following XML inside the <dict> section:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>ms-word</string>
</array>

Step 2: Implement the Detection Logic

Next, create a method to check if the ms-word:// URI can be opened. You can either write platform-specific code or use a shared service with dependency injection.

Option 1: Shared Method with Conditional Compilation

If you want a quick shared method, use conditional compilation to target iOS:

using Microsoft.Maui.ApplicationModel;

public static async Task<bool> IsMicrosoftWordInstalled()
{
#if IOS
    try
    {
        var wordUri = new Uri("ms-word://");
        return await Launcher.CanOpenAsync(wordUri);
    }
    catch
    {
        // Handle any unexpected errors (e.g., permission issues)
        return false;
    }
#else
    // Your existing detection logic for Android, Windows, etc.
    return false;
#endif
}

Option 2: Dependency Injection (Cleaner for Cross-Platform)

For a more maintainable approach, define an interface in your shared project:

public interface IAppInstallationChecker
{
    Task<bool> IsMicrosoftWordInstalled();
}

Then implement it in your iOS project:

using Microsoft.Maui.ApplicationModel;
using YourAppNamespace;

[assembly: Dependency(typeof(iOSAppInstallationChecker))]
namespace YourAppNamespace.Platforms.iOS
{
    public class iOSAppInstallationChecker : IAppInstallationChecker
    {
        public async Task<bool> IsMicrosoftWordInstalled()
        {
            var wordUri = new Uri("ms-word://");
            return await Launcher.CanOpenAsync(wordUri);
        }
    }
}

Inject the interface where you need it, and call the method to get the result.

Key Notes

  • Testing: Make sure to test on a real iOS device (or a simulator with Microsoft Word installed manually). The default simulator doesn't include Word out of the box.
  • Third-Party Editors: This method only detects the official Microsoft Word app. Third-party Word-compatible editors won't respond to the ms-word:// scheme, which aligns with your requirement of checking for Microsoft Word specifically.
  • Error Handling: Wrap the call in a try/catch to handle rare cases (like system-level restrictions blocking the query).

内容的提问来源于stack exchange,提问作者Paul Mariotti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 13:27:31