docs-maui icon indicating copy to clipboard operation
docs-maui copied to clipboard

Add documentation for bundling Swift widgets with .NET MAUI iOS apps

Open Copilot opened this issue 1 month ago • 6 comments

Provides comprehensive documentation for creating iOS widgets using Swift/WidgetKit and bundling them with .NET MAUI apps, addressing the gap in documentation for iOS 14+ widget support.

Changes

  • New documentation page (docs/ios/widgets.md)

    • Widget extension creation in Xcode using WidgetKit
    • Project structure: WidgetBundle, Widget, TimelineProvider, TimelineEntry, Views
    • Build configuration for device and simulator targets
    • MSBuild integration using AdditionalAppExtensions and CodesignEntitlements
    • App Groups setup for data sharing between app and widget
  • Data sharing patterns

    • C# Preferences API with shared App Group ID
    • Swift UserDefaults(suiteName:) for widget-side access
    • Entitlements configuration for both app and extension
  • Communication patterns

    • App → Widget: WidgetKit.WidgetCenterProxy.ReloadTimeLinesOfKind()
    • Widget → App: Deep links via widgetURL() and interactive App Intents
    • App Intents for in-widget buttons and actions
  • TOC placement: iOS section, after "Build apps" subsection

Example: Interactive widget button

struct IncrementCounterIntent: AppIntent {
    func perform() async throws -> some IntentResult {
        let userDefaults = UserDefaults(suiteName: "group.com.contoso.MyApp")
        let count = (userDefaults?.integer(forKey: "WidgetCount") ?? 0) + 1
        userDefaults?.set(count, forKey: "WidgetCount")
        WidgetCenter.shared.reloadTimelines(ofKind: "MyWidget")
        return .result()
    }
}
// In .NET MAUI app
Preferences.Set("WidgetCount", 0, "group.com.contoso.MyApp");

References the official How to Build iOS Widgets with .NET MAUI blog post for complete working examples.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • devblogs.microsoft.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Bundling Swift Widgets and Extensions with .NET MAUI</issue_title> <issue_description>Expand on this https://docs.microsoft.com/en-us/xamarin/ios/platform/ios14/#embedded-widgetkit-support</issue_description>

<agent_instructions>Based on this blog post here: https://devblogs.microsoft.com/dotnet/how-to-build-ios-widgets-with-dotnet-maui/ can you write a documentation page about how to create widgets that can be included in .NET MAUI apps?

The code for this is here: https://github.com/Toine-db/Maui.WidgetExample

Don't link to that repository and only the blog for a reference, but otherwise, come up with your own example and code snippets but make sure they work. We want a generic description of how to do this, but it needs to be a working one.

Investigate if this works for both widgets and extensions and only include extensions if you are 100% sure if it works the same way. Otherwise only talk about widgets.

Note that this is about iOS. Find a place in the TOC that makes sense to put this. We will handle Android separately.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

  • Fixes dotnet/docs-maui#293

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Internal previews

📄 File 🔗 Preview link
docs/ios/widgets.md docs/ios/widgets

Copilot avatar Jan 13 '26 08:01 Copilot