Skip to content
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

Open
chamons opened this issue Jun 22, 2020 · 70 comments
Open

[xcode12] WidgetKit #8933

chamons opened this issue Jun 22, 2020 · 70 comments
Labels
iOS Issues affecting Xamarin.iOS missing-api-bindings requires-swift An issue that requires swift support to fix
Milestone

Comments

@chamons
Copy link
Contributor

chamons commented Jun 22, 2020

This is a feature released in Xcode 12.

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

@chamons chamons added the iOS Issues affecting Xamarin.iOS label Jun 22, 2020
@chamons chamons added this to the xcode12 milestone Jun 22, 2020
@chamons
Copy link
Contributor Author

chamons commented Sep 16, 2020

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.

@chamons
Copy link
Contributor Author

chamons commented Sep 16, 2020

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

@mobilinked
Copy link

@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

@programmation
Copy link

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.

@dajbych
Copy link

dajbych commented Sep 22, 2020

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

@Csaba8472
Copy link

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.

@chamons
Copy link
Contributor Author

chamons commented Sep 22, 2020

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

@michaeldimoudis
Copy link

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

@chamons
Copy link
Contributor Author

chamons commented Sep 23, 2020

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

@michaeldimoudis
Copy link

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

@t9mike
Copy link

t9mike commented Sep 24, 2020

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

@chamons
Copy link
Contributor Author

chamons commented Sep 24, 2020

@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.

@lunoit
Copy link

lunoit commented Sep 26, 2020

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!

@follesoe
Copy link

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) 😅

@michaeldimoudis
Copy link

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:

ERROR ITMS-90075: "This bundle is invalid. The application-identifier entitlement is missing; it should contain your 10-character Apple Developer ID, followed by a dot, followed by your bundle identifier."

I've inspected the package contents and everything seems in order. Is there any known issue around this @chamons?

@chamons
Copy link
Contributor Author

chamons commented Oct 7, 2020

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.

@michaeldimoudis
Copy link

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 Entitlements files, in both the app and widget, I added application-identifier with my full application identifier.
ie:

    <key>application-identifier</key>
    <string>XXXXXXXXXX.com.mysite.myapp</string>

And for the widget

    <key>application-identifier</key>
    <string>XXXXXXXXXX.com.mysite.myapp.mywidget</string>

Note that placeholders $(AppIdentifierPrefix)$(CFBundleIdentifier) did not work.

@JohnHDev
Copy link

JohnHDev commented Oct 10, 2020

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.

@lunoit
Copy link

lunoit commented Oct 10, 2020

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 Entitlements files, in both the app and widget, I added application-identifier with my full application identifier.
ie:

    <key>application-identifier</key>
    <string>XXXXXXXXXX.com.mysite.myapp</string>

And for the widget

    <key>application-identifier</key>
    <string>XXXXXXXXXX.com.mysite.myapp.mywidget</string>

Note that placeholders $(AppIdentifierPrefix)$(CFBundleIdentifier) did not work.

I can confirm that was also the fix for my group-identifier issue above.
Great find @michaeldimoudis !

@dajbych
Copy link

dajbych commented Oct 15, 2020

@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:

2>  /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/user/Library/Caches/Xamarin/mtbs/builds/MyApp/116272d3d5ca5387493a48c56e38ac90/obj/iPhone/Debug/device-builds/iphone8.1-14.0.1/response-file.rsp 
2>  /usr/bin/ditto -rsrc "C:/Users/user/iCloudDrive/Documents/MyApp/MyApp-Widget-Build/Build/Products/Debug-iphoneos/WidgetExtension.appex" bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/PlugIns/WidgetExtension.appex 
2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil -num-threads 4 -z -o bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/../Mono.framework.dSYM bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/Frameworks/Mono.framework/Mono 
2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip -S -x bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/Frameworks/Mono.framework/Mono 
2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil -num-threads 4 -z -o bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app.dSYM bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/MyApp 
2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip -i -s obj/iPhone/Debug/device-builds/iphone8.1-14.0.1/mtouch-symbols.list bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/MyApp
2>  /usr/bin/mdimport bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/../ 
2>  /usr/bin/codesign --verify -vvvv "-R=anchor apple generic and certificate 1[field...] exists and (certificate leaf[field...] exists or certificate leaf[field...] exists)" bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/PlugIns/WidgetExtension.appex 
2>  /usr/bin/codesign --verify -vvvv "-R=anchor apple generic and certificate 1[field...] exists and (certificate leaf[field...] exists or certificate leaf[field...] exists)" bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app 
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

Both the Xamarin.iOS app and the SwiftUI widget extension are successfully signed, but the app is deployed to device without the widget extension:

1>  /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/user/Library/Caches/Xamarin/mtbs/builds/MyApp/116172d3d5ca5387493a48c56e38ac90/obj/iPhone/Debug/device-builds/iphone8.1-14.0.1/response-file.rsp 
1>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil -num-threads 4 -z -o bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/../Mono.framework.dSYM bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/Frameworks/Mono.framework/Mono 
1>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip -S -x bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/Frameworks/Mono.framework/Mono 
1>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil -num-threads 4 -z -o bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app.dSYM bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/MyApp 
1>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip -i -s obj/iPhone/Debug/device-builds/iphone8.1-14.0.1/mtouch-symbols.list bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/MyApp
1>  /usr/bin/mdimport bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/../ 
1>  /usr/bin/codesign --verify -vvvv "-R=anchor apple generic and certificate 1[field...] exists and (certificate leaf[field...] exists or certificate leaf[field...] exists)" bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app/PlugIns/WidgetExtension.appex 
1>  /usr/bin/codesign --verify -vvvv "-R=anchor apple generic and certificate 1[field...] exists and (certificate leaf[field...] exists or certificate leaf[field...] exists)" bin/iPhone/Debug/device-builds/iphone8.1-14.0.1/MyApp.app 
2>Starting deploy 'MyApp' into the device 'My iPhone 6s'...
2>Deploying 'MyApp' into the device 'My iPhone 6s'...
Installing application bundle 'com.dajbych.MyApp' on 'My iPhone 6s'
...
2>Deploy succeeded. The app 'MyApp' has been successfully deployed on My iPhone 6s.
...
Application bundle 'com.dajbych.MyApp' installed on 'My iPhone 6s'

I have noticed that the file in C:\Users\user\Documents\Sources\MyApp\bin\iPhone\Debug\device-builds\iphone8.1-14.0.1\MyApp.app\PlugIns\WidgetExtension.appex is empty. The source file in C:\Users\user\iCloudDrive\Documents\MyApp\MyApp-Widget-Build\Build\Products\Debug-iphoneos\WidgetExtension.appex has 40 kB. Am I doing something wrong, or it is a bug in the build chain?

@JohnHDev
Copy link

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. :)
It is going to be a bit of a slog to get my SwiftUI knowledge up to a level that will mean I can produce anything half decent. Are there any imminent plans to continue developing WidgetKit in C#? If you said it might be available in the next 3 months we would probably wait, otherwise we would need to start learning/deveping in SwiftUI now.

Cheers
John

@wojciech-kulik
Copy link
Contributor

@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.

@JohnHDev
Copy link

JohnHDev commented Oct 18, 2020

@wojciech-kulik

@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.

@wojciech-kulik
Copy link
Contributor

@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.

@JohnHDev
Copy link

@wojciech-kulik well, lets see what Xamarin says.

@dajbych
Copy link

dajbych commented Oct 20, 2020

@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.

@wojciech-kulik
Copy link
Contributor

wojciech-kulik commented Oct 20, 2020

@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 PlugIns directory. If you are using app groups for sharing data, you also need to sign it.

@Jon2G
Copy link

Jon2G commented Nov 18, 2021

@SarthakGz
Working with XCode 13, macOS Monterrey, iPhone SE2 running IOS 15.0.2
The widget never works for me on the simulator by the way so I had to develop it using the real device only.

@SprengerS
Copy link

@SarthakGz
We also use the Xamarin App with an WidgetKit App Extensions. Both have the same AppGroup and we habe NO Problems with data Sharing over the App Group. We are using a SQLite Database which is filled by the App and the Widget and the IntentExtension are reading the data from our SQLite Database.

  • We use MacOS BigSur, Xcode 13 and iOS 15.0
  • I have overwritten the _ExtendAppExtensionReferences Build Target in order to sign our Widget correctly during the Build Process. Signing the AdditionalAppExtension has only worked for an iPhone Distribution Certificate and not for an Apple Distribution´. For Develop builds we use the default Target, but for Distribution we use our Apple Distribution` certificate

@SarthakGz
Copy link

SarthakGz commented Nov 19, 2021

Thanks @SprengerS for the info.I guess I will try with XCode automatically manage signing option if that helps
Though I am creating iOS build with enterprise certificates but that should not make any difference.Will think more about this

@AlexeyStarkov
Copy link

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?

@mnxamdev
Copy link

mnxamdev commented Feb 7, 2022

Same as @AlexeyStarkov ! We are getting the "ditto" build error on VS Mac.

@Jon2G
Copy link

Jon2G commented Feb 8, 2022

Try with a full path for the .appex file in .csproj instead of a relative one.
Ditto can be related to not finding appex file.

@mnxamdev
Copy link

mnxamdev commented Feb 11, 2022

@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:

<ItemGroup>
      <AdditionalAppExtensions Include="$(MSBuildProjectDirectory)/../../My.iOS.Widget">
        <Name>widgetExtension</Name>     
        <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">DerivedData/ios/Build/Products/Debug-iphoneos</BuildOutput>
        <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">DerivedData/ios/Build/Products/Debug-iphonesimulator</BuildOutput>
        <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">DerivedData/ios/Build/Products/Release-iphoneos</BuildOutput>
        <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iphonesimulator' ">DerivedData/ios/Build/Release/AdHoc-iphonesimulator</BuildOutput>
        <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">DerivedData/ios/Build/Products/Release-iphoneos</BuildOutput>
        <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Release|iphonesimulator' ">DerivedData/ios/Build/Products/Release-iphonesimulator</BuildOutput>
    </AdditionalAppExtensions>
  </ItemGroup>

@mnxamdev
Copy link

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?

<Choose>
    <When Condition="'$(Configuration)'!='Debug'">
      <ItemGroup>
          <AdditionalAppExtensions Include="$(MSBuildProjectDirectory)/../../My.iOS.Widget">
            <Name>widgetExtension</Name>     
            <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">DerivedData/ios/Build/Products/Debug-iphoneos</BuildOutput>
            <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">DerivedData/ios/Build/Products/Debug-iphonesimulator</BuildOutput>
            <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">DerivedData/ios/Build/Products/Release-iphoneos</BuildOutput>
            <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iphonesimulator' ">DerivedData/ios/Build/Release/AdHoc-iphonesimulator</BuildOutput>
            <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">DerivedData/ios/Build/Products/Release-iphoneos</BuildOutput>
            <BuildOutput Condition=" '$(Configuration)|$(Platform)' == 'Release|iphonesimulator' ">DerivedData/ios/Build/Products/Release-iphonesimulator</BuildOutput>
        </AdditionalAppExtensions>
      </ItemGroup>
    </When>
  </Choose>

@elpendor
Copy link

elpendor commented Aug 19, 2022

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:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(292,3): warning : The App Extension 'NativeWidget' has an unrecognized NSExtensionPointIdentifier value ('com.apple.widgetkit-extension').

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.

@adam-russell
Copy link

adam-russell commented Aug 19, 2022

@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:
#15598

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

@elpendor
Copy link

@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.

@omatrot
Copy link

omatrot commented Oct 18, 2022

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.

@SwiftNativeDeveloper
Copy link

SwiftNativeDeveloper commented Nov 10, 2022

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.

@wojciech-kulik
Copy link
Contributor

wojciech-kulik commented Nov 11, 2022

@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.

@netzperfekt
Copy link

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

@martic224
Copy link

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.

@adam-russell
Copy link

@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.)

@martic224
Copy link

martic224 commented Mar 2, 2023

@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.

@adam-russell
Copy link

adam-russell commented Mar 2, 2023

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.

@PaoloUbisive
Copy link

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.

@tipa
Copy link

tipa commented Oct 20, 2023

@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

@PaoloUbisive
Copy link

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

@iancona
Copy link

iancona commented Dec 29, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues affecting Xamarin.iOS missing-api-bindings requires-swift An issue that requires swift support to fix
Projects
None yet
Development

No branches or pull requests