question

CodeMan-8556 avatar image
0 Votes"
CodeMan-8556 asked WenyanZhang-MSFT commented

Write a Swift library binding to detect Xamarin

I'm building a native SDK in Swift and I would like to be able to detect at runtime if the app is in Xamarin. My first thought was to use some reflection to determine if Xamarin classes are present by doing something like this:

if NSClassFromString("xamarin-support") != nil
But I don't think that'll actually return true in a Xamarin app since xamarin-support is a file not a class: https://github.com/xamarin/xamarin-macios/blob/main/runtime/xamarin-support.m

Are there any ways I could write some Swift that would detect if the current app is built using Xamarin? Any pre-processors?

dotnet-ios
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have to say I am afraid there is no such configuration,Xamarin.iOS applications run within the Mono execution environment, and use full Ahead of Time (AOT) compilation to compile C# code to ARM assembly language. This runs side-by-side with the Objective-C Runtime.
If you find class xamarin-support or XamarinAssociatedObject, I'm not sure it can be detected.



0 Votes 0 ·

1 Answer

CodeMan-8556 avatar image
0 Votes"
CodeMan-8556 answered

Maybe NSClassFromString("XamarinAssociatedObject")?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.