-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xcode12] WidgetKit #8933
Comments
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. |
See the PR for an example. More details in a future blog post as well. |
@chamons And another idea related to the tech you are using:
Best Regards, Philip |
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. |
Same problem here. Visual Studio 2019 version 16.7.4 ends the build with the following error: |
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. |
@programmation (and others here) - Please post a full build log |
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 The PR is here: chamons/xamarin-ios-swift-extension#1 Cheers |
Love the PR, it does not surprise me that Apple broke the Widget after the Beta I wrote that in. |
Above PR is updated and merged, everything is working in Visual Studio now, no more |
Is it possible to make an API call into my Xamarin phone app from the Swift widget to get data to display? |
@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. |
Thanks for the great demo app Chris! container_create_or_lookup_path_for_platform: client is not entitled I did include all group entitlements and also registered them at Apple Developer account.. |
Love the fact that we can get Widgets working in Xamarin.iOS already. Don't mind having to implement the widget in SwiftUI. This may be a bit on the side - but at least a tip to make this easier for .NET developers not familiar with xcode builds, would be to describe how to build the native extension from the command line. We are using AppCenter for CI, and before I invest time in building the widget, I need to figure out how to build it (I expect I will spend more time on building the extension and signing it, than actually implementing the SwiftUi and the data exchange between the Xamarin app and the Swift UI widget) 😅 |
I'm finding it impossible to upload an app with a Widget to Apple. When I upload the app, this is the only error I am getting:
I've inspected the package contents and everything seems in order. Is there any known issue around this @chamons? |
No known issue - I'd verify all of your signing/entitlement/info.plsits. Without a sample showing it, I'm not sure anyone will be able to help you here. Getting signing right is sometime non-trivial. |
Thanks. So after banging my head on a number of long nights, throwing everything including the kitchen sink at my code, I can finally build a version that is accepted by the App Store. I have no idea why this worked, but to save other people from experiencing the same issue, this was my fix: In the
And for the widget
Note that placeholders |
Hi @chamons, when do you think direct support for WidgetKit in C# will be available? This information will be useful with regards to our current scheduling plans, wether to go for SwiftUI right now, or wait for C# if its only a few months away. Your example looks good, but having to use SwiftUI largely defeats the point of using Xamarin.iOS. |
I can confirm that was also the fix for my group-identifier issue above. |
@Csaba8472 Thank you, I didn't know that Visual Studio does not copy the extension code from Windows to Mac and does not build it there. I'm able to create and build a SwiftUI app with widget on Mac with Xcode and deploy it to my iPhone. When I copy the widget extension to Windows and set AdditionalAppExtensions in the Xamarin.iOS project correctly, Visual Studio builds the project:
Both the Xamarin.iOS app and the SwiftUI widget extension are successfully signed, but the app is deployed to device without the widget extension:
I have noticed that the file in |
Hi @chamons, when do you think direct support for WidgetKit in C# will be available? I have your example working (thank you for that!) in so far as I can see a widget and add it to the simulator, although I don't see any data in the widget itself, Ive probably forgotten to do something there. However I have zero knowledge of working in SwiftUI, I did some ObjC back in the day but I chose Xamarin.iOS for a reason. :) Cheers |
@JohnHDev I think it would be too much effort to map XAML to SwiftUI. Therefore, I think native WidgetKit will be the only option, unfortunately. |
I am actually referring to writing widgets in Xamarin.iOS, so C#. Anything above that would be a bonus. But as a minimum I would want to see C# support. After all, that is the foundation of what Xamarin provides. |
@JohnHDev Anyway, I think it would be a huge effort to support that, that’s why I think it won’t happen. I think in best case scenario, there will be some support for Widget project in VS, but you will have to work on that in Xcode. Similarly to Android, where you can add xml layouts. Maybe here you will be able to add SwiftUI files. I already made widgets in Xcode in my project and I recommend to do the same, because even if they try to provide somehow some support for swiftui, it will take a long time IMO. SwiftUI is nice and easy, but the only problem is if you need API then you will need to rewrite your service and models to Swift. |
@wojciech-kulik well, lets see what Xamarin says. |
@wojciech-kulik Are you using Visual Studio for Mac, or Visual Studio 2019? I already made my Widget in Xcode and SwiftUI and it works fine when deployed from Xcode, but I not able to integrate it into my Xamarin.iOS application in Visual Studio 2019 on Windows. |
@dajbych I'm using Visual Studio For Mac. I've seen some issue somewhere, that on Windows doesn't work copying additional extensions. So maybe that's the problem. As a workaround, you could try to add build phase and copy your appex file manually into your bundle to |
@SarthakGz |
@SarthakGz
|
Thanks @SprengerS for the info.I guess I will try with XCode automatically manage signing option if that helps |
I've tried everything that you all advised but I still have "ditto" build error. Does anyone know anything about any new tips/tricks or hacks/workarounds regarding Xamarin and Widgets? |
Same as @AlexeyStarkov ! We are getting the "ditto" build error on VS Mac. |
Try with a full path for the .appex file in .csproj instead of a relative one. |
@AlexeyStarkov I fixed my ditto issue with some tinkering. I think it started working once I moved my Xcode project folder to be at the same level as the example and also fixed a combination of include path and name in the AdditionalAppExtensions section of the csproj. I also added other configurations to match my Xamarin project but not sure if they are necessary:
|
I got this working finally on VS Mac but upon checking in, another developer on my team couldn't build from Windows and kept getting a "ditto" error. They primarily use VS on Windows so this is really problematic for us. Since they mainly will use Debug config we found a solution that wrapped the AdditionalAppExtension section like this. Of course any time we need to develop on the widget we'll need to edit this. Does anyone know how to detect VS Mac within the csproj file so we can at least not have to crack open and edit this every time?
|
Hey guys, I'm having some trouble with it, hopefully you can think of something: App works fine after I've added every reference I needed. I can launch it on both simulator and real devices, all fine. But I can't seem to deploy an IPA build using an Adhoc profile (I'm guessing targeting release will cause the same thing). Deploying the Adhoc build via Visual Studio using the same provisioning profiles works fine, but if I archive it, build an IPA and sign it, it won't. I'm guessing it's a signing issue, specifically with the widget part of this. If I remove the widget, I can deploy the IPA via Xcode (or any other means) just fine. I've tried everything here, I've specified the application-identifier tag in both projects and nothing. Only thing that looks weird is this: But then again, everything works perfect on every possible configuration (debug/release on simulators and real devices) I've tried. It just won't work when I build an IPA and deploy it with this widget included. I also have another widget, using the old framework, different identifier that this one. I don't think it's related to this. |
@elpendor code signing app extensions (including Widgets) doesn't work correctly in Xamarin.iOS 15.10+ Not sure if that covers the version you're using, but I would guess it probably does. Here's the issue related to that: I get that same weird error message, for what it's worth, but I haven't seen any actual issues with the build (other than the code signing, obviously) and I've had an app in the App Store for a while with it. You can try using Xamarin.iOS 15.8.x (where code signing still works for extensions) to see whether that fixes it, or you could also build the IPA then break it apart and code sign it manually (as the workaround mentioned in the issue I linked above). Update: Just in case you want to try the old version or Xamarin.iOS and need a download link, here's one: https://aka.ms/xvs/pkg/macios/15.8.0.5 |
@adam-russell That was indeed the issue I was having, thanks. Older 15.8.x seems to be building the IPA correctly and I can deploy it just fine. Hopefully there won't be any similar issues when I upload it to the store. Again, thanks A LOT for your help. |
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).
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 also have this warning
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. |
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. |
@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. |
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). |
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. |
@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):
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 (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.) |
@adam-russell I did try adding an additional app extension block but that didn't work for me. Edit: |
Great, looks like you got it working! FYI, in case this is also helpful, my |
Hi guys, it's my first time writing a Widget in iOS and I'm facing the same difficulties of @martic224 and @netzperfekt. |
@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. |
@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. |
This is a feature released in Xcode 12.
For now, this is what is known: https://developer.apple.com/widgets/
The text was updated successfully, but these errors were encountered: