Skip to content

[xcode12] WidgetKit #8933

Open
Open

Description

@chamons

This is a feature released in Xcode 12.

For now, this is what is known: https://developer.apple.com/widgets/

Activity

  1. added
    iOS
    on Jun 22, 2020
  2. added this to the xcode12 milestone on Jun 22, 2020
  3. chamons commented on Sep 16, 2020

    @chamons
    ContributorAuthor

    Just an update on this - direct support for WidgetKit in C# did not make it this year, and isn't in our initial Xcode 12 support release.

    However, we did add support for using a new AdditionalAppExtensions property in your project to embed Swift extensions in your Xamarin.iOS project.

    More complete support is on our backlog for future possible features now.

  4. chamons commented on Sep 16, 2020

    @chamons
    ContributorAuthor

    See the PR for an example. More details in a future blog post as well.

  5. mobilinked commented on Sep 21, 2020

    @mobilinked

    @chamons
    Thank you for the update. If it's convenient, can Xamarin team share us a simple guide from project setting up to release to App Store?

    And another idea related to the tech you are using:

    • Expose xamarin lib project to an XCode framework
    • And use a XCode framework as a xamarin project lib

    Best Regards,

    Philip

  6. programmation commented on Sep 22, 2020

    @programmation

    I downloaded the sample app from https://github.com/chamons/xamarin-ios-swift-extension/blob/master/App/TestApplication/TestApplication.csproj#L143 but the demo Extension doesn't compile with Xcode 12 GM.

  7. dajbych commented on Sep 22, 2020

    @dajbych

    Same problem here. Visual Studio 2019 version 16.7.4 ends the build with the following error: "ditto" exited with code 1.

  8. Csaba8472 commented on Sep 22, 2020

    @Csaba8472

    this happened to me when path(AdditionalAppExtensions Include + BuildOutput), didn't point to the widget which xcode built. Haven't tried it on windows yet, so @dajbych your issue could be something else.

  9. chamons commented on Sep 22, 2020

    @chamons
    ContributorAuthor

    @programmation (and others here) - Please post a full build log

  10. michaeldimoudis commented on Sep 23, 2020

    @michaeldimoudis

    Hi @chamons thanks for your work with this. I created a draft PR to get the sample compiling in Xcode 12 GM. However building the Xamarin iOS app with the widget in Visual Studio is impossible for me atm, due to the ditto compile error.

    The PR is here: chamons/xamarin-ios-swift-extension#1

    Cheers

  11. chamons commented on Sep 23, 2020

    @chamons
    ContributorAuthor

    Love the PR, it does not surprise me that Apple broke the Widget after the Beta I wrote that in.

  12. michaeldimoudis commented on Sep 23, 2020

    @michaeldimoudis

    Above PR is updated and merged, everything is working in Visual Studio now, no more "ditto" exited with code 1 error. Thanks @chamons!

  13. t9mike commented on Sep 24, 2020

    @t9mike

    Is it possible to make an API call into my Xamarin phone app from the Swift widget to get data to display?

  14. chamons commented on Sep 24, 2020

    @chamons
    ContributorAuthor

    @t9mike - Not easily. The WidgetKit extension is in a separate process space than your main application, and can be invoked arbitrarily by Apple to get more timeline data.

    It would be theoretically possible to use something like https://github.com/mono/Embeddinator-4000 to start up mono and then invoke C#, but that project has been in community support for awhile and isn't in the best shape today.

    Due to this, I believe the best approach is to either serialize data in your application (or background task) to a common location (what the sample does) or fetch the data from a shared web service.

  15. lunoit commented on Sep 26, 2020

    @lunoit

    Thanks for the great demo app Chris!
    Based on your example, I managed to create a widget extension for my app, using group identifiers.
    All is working just fine in the simulator. Also, running directly from Xcode (swiftUI) on a real device works great.
    When I run the app from VS for Mac however (hybrid mode) on a real device, I get following error in the console log of the device:

    container_create_or_lookup_path_for_platform: client is not entitled
    container_create_or_lookup_app_group_path_by_app_group_identifier: client is not entitled

    I did include all group entitlements and also registered them at Apple Developer account..
    Any idea what I'm missing?
    Thanks!

  16. 45 remaining items

  17. omatrot commented on Oct 18, 2022

    @omatrot

    Hello everyone.

    I just discovered the WidgetKit support in Xamario.iOS and would like to build and app starting with the sample.

    My Setup is a MacBook Pro M1 with Xcode and VS 2022 and an iPhone 8 Plus (iOS 16).

    Visual Studio Enterprise 2022 for Mac Preview
    Version 17.4 Preview (17.4 build 2285)
    Installation UUID: d8f305fe-c05c-4913-bb1a-fddb552703a3
    
    Runtime
    .NET 6.0.9 (64-bit)
    Architecture: Arm64
    
    Roslyn (Language Service)
    4.4.0-3.22461.4+8ab250290a4010c11a21521f78dbc87dbb7aac81
    
    NuGet
    Version: 6.3.1.1
    
    .NET SDK (Arm64)
    SDK: /usr/local/share/dotnet/sdk/7.0.100-rc.2.22477.23/Sdks
    SDK Versions:
    	7.0.100-rc.2.22477.23
    	6.0.402
    	6.0.401
    	6.0.300
    	6.0.203
    	6.0.202
    MSBuild SDKs: /Applications/Visual Studio (Preview).app/Contents/MonoBundle/MSBuild/Current/bin/Sdks
    
    .NET SDK (x64)
    SDK Versions:
    	6.0.402
    	6.0.401
    	6.0.300
    	6.0.203
    	6.0.103
    	5.0.408
    	5.0.406
    	3.1.424
    	3.1.423
    	3.1.419
    	3.1.418
    	3.1.417
    
    .NET Runtime (Arm64)
    Runtime: /usr/local/share/dotnet/dotnet
    Runtime Versions:
    	7.0.0-rc.2.22472.3
    	6.0.10
    	6.0.9
    	6.0.5
    	6.0.4
    
    .NET Runtime (x64)
    Runtime: /usr/local/share/dotnet/x64/dotnet
    Runtime Versions:
    	6.0.10
    	6.0.9
    	6.0.5
    	6.0.3
    	5.0.17
    	5.0.15
    	3.1.30
    	3.1.29
    	3.1.25
    	3.1.24
    	3.1.23
    
    Xamarin.Profiler
    Version: 1.8.0.19
    Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
    
    Updater
    Version: 11
    
    Apple Developer Tools
    Xcode 14.0.1 (21336)
    Build 14A400
    
    Xamarin.Mac
    Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.
    
    Xamarin.iOS
    Version: 16.0.0.72 (Visual Studio Enterprise)
    Hash: 6756a1146
    Branch: release/6.0.4xx-xcode14
    Build date: 2022-09-21 08:51:06-0400
    
    Xamarin Designer
    Version: 17.4.0.125
    Hash: fa50256a21
    Branch: remotes/origin/main
    Build date: 2022-10-05 17:25:28 UTC
    
    Xamarin.Android
    Version: 13.1.0.1 (Visual Studio Enterprise)
    Commit: xamarin-android/d17-4/13ba222
    Android SDK: /Users/oliviermatrot/Library/Developer/Xamarin/android-sdk-macosx
    	Supported Android versions:
    		8.0  (API level 26)
    		12.0 (API level 31)
    		8.1  (API level 27)
    		11.0 (API level 30)
    		10.0 (API level 29)
    		9.0  (API level 28)
    
    SDK Command-line Tools Version: 7.0
    SDK Platform Tools Version: 33.0.2
    SDK Build Tools Version: 33.0.0
    
    Build Information: 
    Mono: a96bde9
    Java.Interop: xamarin/java.interop/d17-4@fcc33ce2
    SQLite: xamarin/sqlite/3.39.3@23e1ae7
    Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a
    
    Microsoft Build of OpenJDK
    Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
    11.0.12
    Android Designer EPL code available here:
    https://github.com/xamarin/AndroidDesigner.EPL
    
    Eclipse Temurin JDK
    Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
    1.8.0.302
    Android Designer EPL code available here:
    https://github.com/xamarin/AndroidDesigner.EPL
    
    Android SDK Manager
    Version: 17.4.0.53
    Hash: 0fb3646
    Branch: remotes/origin/HEAD
    Build date: 2022-10-05 17:25:33 UTC
    
    Android Device Manager
    Version: 0.0.0.1205
    Hash: c44f311
    Branch: main
    Build date: 2022-10-05 17:25:33 UTC
    
    Build Information
    Release ID: 1704002285
    Git revision: ebd916dfa85cbe4872c6143aef3589ccff835d67
    Build date: 2022-10-05 17:22:42+00
    Build branch: release-17.4
    Build lane: release-17.4
    
    Operating System
    Mac OS X 12.6.0
    Darwin 21.6.0 Darwin Kernel Version 21.6.0
        Mon Aug 22 20:20:05 PDT 2022
        root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64
    

    I've cloned the sample repo and replaced certificates and provisioning profiles with mine. Here are my current experience with the sample, which is not very good so far:

    • I do not understand how the Swift UI App could share the same bundle ID with the Xamarin App. Is this because in the end it will not, given the fact that the Xamarin App embed only the widget ?
    • How can I debug such an hybrid app ? At this time I can't install the Xamarin App alone on the device. The message states that its integrity could not be verified.
      • I can install the SwiftUIApp with its Widget first, then the Xamarin App. In this scenario, it works.
      • But from now if I start the application from Visual Studio, this is the SwiftUIApp that is launched not he Xamarin one.
      • And last but not least, Xamarin asks me to launch the app in debug mode because it is signed with a distribution profile, which is not true, I'm using a developer profile.

    I also have this warning

    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(3,3): Warning: The App Extension 'NativeWidget' has an unrecognized NSExtensionPointIdentifier value ('com.apple.widgetkit-extension').
             (TestApplication)
    

    I am not having these problems with the simulator (iPhone 14/ iOS 16).

    Which would indicate that Code signing is broken again ? Should I reopen https://github.com/xamarin/xamarin-macios/issues/15598 ?

    Any help appreciated.

  18. SwiftNativeDeveloper commented on Nov 10, 2022

    @SwiftNativeDeveloper

    Is there any official support coming for this? If an app built with Xamarin wants to make a Live Activity (Xcode 14.1), simply put, you can't because it requires the UI to be made with SwiftUI and WidgetKit. I know that others have suggested some workarounds but there isn't any official support for WidgetKit provided by or approved by Microsoft.

    I didn't see any mention of ActivityKit in the Xcode 14.1 milestone.

    https://developer.apple.com/documentation/activitykit

    This translates to zero support for the new Dynamic Island hardware feature available in iPhone 14 Pro / Pro Max.

  19. wojciech-kulik commented on Nov 11, 2022

    @wojciech-kulik
    Contributor

    @SwiftNativeDeveloper I don't think that Xamarin will ever get support for features related to SwiftUI. That's the problem with cross-platform technologies, they sometimes hit the wall. In terms of Xamarin, I think it would be pretty hard to apply their current approach to SwiftUI. That's why nothing happens in this matter and no official news appears.

    The only hope is to write some code natively and try to combine it with the current Xamarin app.

  20. added
    requires-swift
    on Jan 20, 2023
  21. netzperfekt commented on Jan 24, 2023

    @netzperfekt

    I have tried this so far and it seems to work quite well. However, if I want to create a configurable widget, the configuration.intent file must contain the target of the main app in Xcode (see https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget).
    This doesn't seem to work with Xamarin, and the widgets configuration is not working properly (no entry fields are shown and an error "unable to load" appears).
    Is there a trick or an idea for this?

    screenshot_382

  22. martic224 commented on Mar 2, 2023

    @martic224

    I have tried this so far and it seems to work quite well. However, if I want to create a configurable widget, the configuration.intent file must contain the target of the main app in Xcode (see https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget). This doesn't seem to work with Xamarin, and the widgets configuration is not working properly (no entry fields are shown and an error "unable to load" appears). Is there a trick or an idea for this?

    screenshot_382

    I'm also wondering how to create a configurable widget. I was able to get something working natively, but when I load the widget Xamarin Forms the configuration doesn't work. I get a similar 'Unable to load' message.

  23. adam-russell commented on Mar 2, 2023

    @adam-russell

    @martic224 @netzperfekt Not sure how helpful this is, but I've had an Intents extension working as configuration for a widget in a production app for a while across many builds (the app itself is Xamarin Forms, and I have extensions for the widget, intents, and watch on iOS). It was actually pretty straightforward to add -- it just needs to be another AdditionalAppExtension in the .csproj file.

    Here's the relevant section of my .csproj with the project names replaced, in case it's helpful (which is really the same as the widget extension):

    <AdditionalAppExtensions Include="$(MSBuildProjectDirectory)/../ProjectPath"> <Name>ProjectIntentsExtension</Name> <BuildOutput Condition="'$(Platform)' == 'iPhone'">build/Release-iphoneos</BuildOutput> <BuildOutput Condition="'$(Platform)' == 'iPhoneSimulator'">DerivedData/ProjectPath/Build/Products/Debug-iphonesimulator</BuildOutput> </AdditionalAppExtensions>

    I would think if the intent works fine when you debug it/the widget from Xcode, that just bundling it into your Xamarin build with AdditionalAppExtensions should work OK, but maybe there's a step I did that I'm not realizing. I didn't try to package my main stub Swift app into the intents extension or anything like that.

    (As an aside, with more stuff I've added to extensions over time, I've also had to add too much "bridge" code where I basically have much of the "same" code written in C#/XAML and Swift/SwiftUI at the same time to display the same things in Xamarin and in SwiftUI. I'm currently working on replacing my main Xamarin app with a native Swift app on iOS/iPadOS, but YMMV and your approach may vary.)

  24. martic224 commented on Mar 2, 2023

    @martic224

    @adam-russell I did try adding an additional app extension block but that didn't work for me.
    I think it's because in Xcode I can set the widget.intentdefinition to be a Target Member of the native app and widget but I haven't found a way to do that nicely in Xamarin forms.
    Do you have any other tips?

    Edit:
    I got it working finally. I added the intentdefinition file as a link to my Xamarin forms ios project in the reference folder and set the Build Action to 'EmbeddedResource'.
    And as Adam stated above, you need another AdditionalAppExtentsions block for the intent project.

  25. adam-russell commented on Mar 2, 2023

    @adam-russell

    Great, looks like you got it working!

    FYI, in case this is also helpful, my .intentdefinition is not in the main app in the packaged IPA that I can see. It's in both my widget .appex and my intents .appex, though, which are both in the PlugIns folder inside the IPA.

  26. PaoloUbisive commented on Oct 20, 2023

    @PaoloUbisive

    Hi guys, it's my first time writing a Widget in iOS and I'm facing the same difficulties of @martic224 and @netzperfekt.
    Since some of you managed to make it work, could you please share a sample project or something similar to a guide?
    It would really help a lot.

  27. tipa commented on Oct 20, 2023

    @tipa

    @PaoloUbisive try this example: AppWithWidget.zip

    Unzip and run the run_app.sh script. It should build the app and deploy to your simulator. You will have to setup the Xcode project, signing, certificates etc. if you want to run it on a physical device or publish the app.
    I haven't released an app with a widget extension to the store myself, so maybe there are problems that I haven't encountered yet

  28. PaoloUbisive commented on Oct 30, 2023

    @PaoloUbisive

    @tipa I finally managed to try your project and after some modifications it worked, thank you so much!

  29. iancona commented on Dec 29, 2023

    @iancona

    @tipa I finally managed to try your project and after some modifications it worked, thank you so much!

    what type of modifications you made? I'm wasting so many hours.. I signed everything correctly and changed bundleId/applicationId..

    I think the issue could be the path but don't understand I should set it, I left it how it was in the @tipa project. It gives me MSB6006 "ditto" error like someone experienced.

  30. ivmirx commented on Apr 15, 2025

    @ivmirx

    @PaoloUbisive try this example: AppWithWidget.zip

    @tipa thanks a lot, it was a lifesaver after many hours of struggle with configs. In the past, Message stickers worked well from a .csproj, but something broke lately. So I configured them from Xcode and added as a native project.

    Ended up moving the contents of run_app.sh into iOS .csproj and now it runs from Rider too, both on simulator and device:

    <PropertyGroup>
        <SdkName Condition="'$(RuntimeIdentifier)' == 'iossimulator-x64'">iphonesimulator</SdkName>
        <SdkName Condition="'$(RuntimeIdentifier)' == 'ios-arm64'">iphoneos</SdkName>
    </PropertyGroup>
    <Target Name="DebugPrint" BeforeTargets="Build">
        <Message Text="Platform: $(Platform), SdkName: $(SdkName), Configuration: $(Configuration)" Importance="High" />
    </Target>
    <Target Name="BuildStickerExtension" BeforeTargets="Build">
      <Exec Command="xcodebuild -project &quot;$(MSBuildProjectDirectory)/native/StickerPack.xcodeproj&quot; -configuration $(Configuration) -target StickerPackExtension -sdk $(SdkName)" />
    </Target>
    <Target Name="CleanStickerExtension" AfterTargets="Clean">
        <Exec Command="xcodebuild clean -project &quot;$(MSBuildProjectDirectory)/native/StickerPack.xcodeproj&quot; -configuration $(Configuration) -target StickerPackExtension -sdk $(SdkName)" />
    </Target>
    <ItemGroup>
      <ProjectReference Include="..\Core\Core.csproj" />
      <AdditionalAppExtensions Include="./native">
        <Name>StickerPackExtension</Name>
        <BuildOutput Condition="'$(ComputedPlatform)' == 'iPhone'">build/$(Configuration)-iphoneos</BuildOutput>
        <BuildOutput Condition="'$(ComputedPlatform)' == 'iPhoneSimulator'">build/$(Configuration)-iphonesimulator</BuildOutput>
      </AdditionalAppExtensions>
    </ItemGroup>
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    iOSmissing-api-bindingsrequires-swift

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions