xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.48k stars 514 forks source link

MusicKit bindings #17894

Open aspeckt-112 opened 1 year ago

aspeckt-112 commented 1 year ago

Hi.

I apologise if this isn't the correct place to ask this question. I'm aware of the sample here (https://github.com/xamarin/ios-samples/tree/main/ios11/MusicKitSample) but it's not exactly what I'm looking for. I'm talking about the MusicKit Apple Music API introduced in iOS15 here: https://developer.apple.com/documentation/musickit/using_musickit_to_integrate_with_apple_music.

I've had a look through the source here: https://github.com/xamarin/xamarin-macios/tree/main/src and I can't see a MusicKit namespace. Is it fair to assume it's not been bound yet?

Steps to Reproduce

  1. In any Xamarin,iOS class, attempt to bring in the namespace MusicKit with "using MusicKit"

Expected Behavior

The same classes / methods available to me in the sample here should be available to me: https://developer.apple.com/documentation/musickit/using_musickit_to_integrate_with_apple_music are available.

Actual Behavior

Compiler error CS0246: The type or namespace not found

Environment

Version information ``` Microsoft Visual Studio Community 2022 Version 17.5.3 VisualStudio.17.Release/17.5.3+33516.290 Microsoft .NET Framework Version 4.8.09032 Installed Version: Community ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 17.5.318.41597 ASP.NET and Web Tools Azure App Service Tools v3.0.0 17.5.318.41597 Azure App Service Tools v3.0.0 Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 17.5.318.41597 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 4.5.0-6.23128.14+651d32d8017cfcc60fcbd67383601fa9a3deb145 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Extensibility Message Bus 1.4.3 (main@2a4517a) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. GitHub Copilot 1.77.2.0 (v1.77.2.0@570999d7d) GitHub Copilot is an AI pair programmer that helps you write code faster and with less work. GitHub Copilot Agent 1.77.9225 (v1.77.0) Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.5.9 (11975e6) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Razor (ASP.NET Core) 17.5.2.2316603+9f1b6856460af1e592d387ebef416eadddac453f Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 17.2.40119.0 Microsoft SQL Server Data Tools StylerPackage Extension 1.0 StylerPackage Visual Stuido Extension Detailed Info ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 17.0.20105.2003 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.5.0-6.23128.14+651d32d8017cfcc60fcbd67383601fa9a3deb145 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 17.5.0-beta.23053.5+794b7c259d9646a7eb685dad865aa27da7940a21 Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info Xamarin 17.5.0.173 (d17-5@33e727c) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.5.3.46 (remotes/origin/d17-5@e4dd80b2bb) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.5.41 (ba80d05) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.2.0.0 (d17-5/797e2e1) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 6dd9def Java.Interop: xamarin/java.interop/main@149d70fe SQLite: xamarin/sqlite/3.40.0@fdc1e34 Xamarin.Android Tools: xamarin/xamarin-android-tools/main@9f02d77 Xamarin.iOS and Xamarin.Mac SDK 16.2.0.5 (7738c90c9) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Again, I apologise if I'm not asking in the correct place here. I'm just looking to make sure my understanding of the situation is correct.

rolfbjarne commented 1 year ago

It seems MusicKit is only available using Swift, and not Objective-C, which means we're unfortunately not able to create bindings at this moment.

As of today, the only way to use a swift library is via a proxy library, the general idea is described here learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift basically you would need to expose the MusicKit Apis you need via a Swift glue layer that exposes the method via the swift bridge header and then creating a C# binding project for this.

The plan is for us to eventually provide these bindings, but it's a lot of work, so I'm not sure when that might be.

aspeckt-112 commented 1 year ago

Thanks for the reply.

I've been using Xamarin for years, and following along (lurking) with the development here. I figured it would be something like that, but I just wanted to make sure my understanding of the situation was 100% correct before attempting to do anything myself.

Thanks again, have a good rest of your day!

mrlife commented 1 month ago

Hi @aspeckt-112, did you go down this path and did you have any luck? I'm considering whether to do this and wondered how it went if you tried it. Thanks!

aspeckt-112 commented 1 month ago

Hey @mrlife

I ended up just writing the app in Swift. Not the answer you want I’m sure, but that was my choice.

mrlife commented 1 month ago

@aspeckt-112, thanks for writing me back!

Did you go that route after looking into creating all the bindings? Looks like it may be a lot of work, I'm not sure yet

How was it going from .NET/C# to Swift/SwiftUI -- really different? I would consider this but am not quite ready to let go of the MAUI/C#/web approach yet.

aspeckt-112 commented 1 month ago

@mrlife no problem.

That’s pretty much it. I was on a tight(ish) deadline, I guesstimated just doing the binding alone would take as long as just writing everything from scratch in Swift.

I’ve written a good deal of Swift since it came out, and I’ve not found it particularly hard going back and forth. The biggest problem is remembering how Xcode works every few months. The language itself is awesome. I don’t regret my approach.