-
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
Unable to bind native iOS framework that uses Async/Await in iOS 13 #13605
Comments
Hi, @4brunu - I don't believe that Swift functions taking closures are p-invokable. When @stephen-hawley returns next year, he will be able to confirm that. Until then, we will leave this issue open. |
See https://forums.swift.org/t/concurrency-interoperability-with-objective-c/41616 in particular the section on using blocks. You can in theory bind that to C# with our BlockLiteral, but it's a bit complicated. If you want to go down that road consider dropping by https://aka.ms/dotnet-discord #apple if you have questions. |
Hi @rachelkang and @chamons, thanks for reaching out 🙂 Maybe I didn't explain myself well. The issue here is not related to calling a Swift function that takes a closure. The issue is related to the use of Async/Await with the new backwards compatible mode, and running on iOS 13 and 14. To sum up, the issue is not calling Async/Await code from C#, the issue is that Xamarin seems that is not injecting the new support library related to the new concurrency mode, therefore the code above works fine on iOS 15 but it crashes on iOS 13 and 14, because Async/Await was only introduced in iOS 15, and only works on iOS 13 and 14 when the new support library related to the new concurrency mode is present. This is the code that I have inside my native iOS Framework.
The function functionThatCallsPrivateAsyncFunction is compatible with Objective-c. But when I call the function functionThatCallsPrivateAsyncFunction from Xamarin iOS, it works on iOS 15, but it crashes on iOS 13 and 14 with the following error.
I think the issue is that for the Swift 5.5 to support Async/Await in older versions of iOS (13 and 14) it needs a new support library related to the new concurrency mode. But I think Xamarin is not injecting this new support library, therefore the code above works correctly on iOS 15, but not on iOS 13 and 14. All the Async/Await code is only used internally inside the iOS native framework and only referenced in a privately inside the Framework, and never referenced directly by Xamarin iOS. |
@4brunu Thanks for elaborating. Could you try using https://www.nuget.org/packages/Xamarin.iOS.SwiftRuntimeSupport/ and let us know how that works for you? |
@rachelkang I just tested it and it still crashes. |
I got this working by enable in Xcode the setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES. This confirms that this issue is caused by the the missing Swift standard libraries. So updating the package https://www.nuget.org/packages/Xamarin.iOS.SwiftRuntimeSupport/ to the last version should fix this issue. |
Please give this version a try. I had some major trouble updating that library, which has been unmaintained for a few years, but I think that should work. Xamarin.iOS.SwiftRuntimeSupport.0.2.1.nupkg.zip You may need to add it to your local nuget feed, I can dig up instructions if needed on that. |
It worked! |
I'll look into it, but to be honest all of the relevant people may be on vacation, so there may be some delay. |
Sure, thanks for helping 🙂 |
First of all thanks for fix. Any tentative plan to publish this? We are having the similar issue code sign failing after upgrading to xcode 13.2.1 and your 0.2.1 package addressed that as well. Waiting for the published version. Please let us know and Thank you once again! |
any update on the publish date @chamons? Appreciate your help on this. Thanks! |
Steps to Reproduce
Expected Behavior
With the release of Xcode 13.2, Async/Await is now backwards compatible and works on iOS 13 and above.
So Async/Await is expected to work on iOS 13 and above.
Actual Behavior
Xamarin.iOS throws a Native Crash Reporting when calling a method of a native iOS framework that uses async/await on iOS 13.
Environment
Build Logs
https://gist.github.com/4brunu/55e4c18a9b8455cb492c01a84026ccdc
Example Project (If Possible)
The directory SwiftAsyncAwaitFramework contains a native iOS Framework that uses Async/Await on iOS 13 and above, and also a native sample app SwiftAsyncAwaitAppExample, to test the Async/Await on iOS 13 and above, and it works.
The directory SwiftAsyncAwaitBinding contains the xamarin binding of the native iOS library.
The directory SwiftAsyncAwaitExample contains a Xamarin app to test the xamarin binding of the native iOS library.
SwiftAsyncAwaitExample.zip
The text was updated successfully, but these errors were encountered: