Skip to content

Commit

Permalink
fix ios link error for apps consuming .nupkg
Browse files Browse the repository at this point in the history
Xamarin has limited support for `.xcframework` files, they do not have a
built in working solution for NuGet packages yet.
This works around the issue by including `OneSignal.xcframework` as-is
in the `.nupkg`. It also includes a `.target` file which is setting to
add the `OneSignal.xcframework` as a native reference.
See the comment in the `Com.OneSignal.nuspec` file for more details.

The items under `<NativeReference>` in `Com.OneSignal.targets` is from
`OneSignal.iOS.Binding.csproj` in this repo.

This was added based on the recommendations from:
   - xamarin/xamarin-macios#10819 (comment)
  • Loading branch information
jkasten2 committed Nov 22, 2021
1 parent 9144062 commit 63418a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Com.OneSignal.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@

<!--Xamarin.iOS Unified-->
<file src="Com.OneSignal.iOS\bin\Release\*OneSignal.*" target="lib\Xamarin.iOS10" />

<!-- Workaround to support .XCFramework for iOS -->
<!-- Resources includes the full OneSignal.XCFramework.
iOS.Binding project has NoBindingEmbedding = true so it isn't also bundled in the .dll -->
<file src="OneSignal.iOS.Binding\bin\Release\OneSignal.iOS.Binding.resources\**" target="content\Com.OneSignal.iOS.resources" />
<!-- This is a .target files that gets used by project that consumes the NuGet package.
This copies out the OneSignal.xcframework from the resources folder and adds a NativeReference to it in the app project. -->
<file src="OneSignal.iOS.Binding\Com.OneSignal.targets" target="build\Xamarin.iOS10\" />
</files>
</package>
16 changes: 16 additions & 0 deletions OneSignal.iOS.Binding/Com.OneSignal.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BeforeCompile">
<ItemGroup>
<BindingResources Include="$(MSBuildThisFileDirectory)../content/Com.OneSignal.iOS.resources/**/*.*" />
</ItemGroup>
<Copy SourceFiles="@(BindingResources)" DestinationFolder="$(TargetDir)/Com.OneSignal.iOS.resources/%(RecursiveDir)" ContinueOnError="false" />
<ItemGroup>
<NativeReference Include="$(TargetDir)/Com.OneSignal.iOS.resources\OneSignal.xcframework">
<Kind>Framework</Kind>
<SmartLink>False</SmartLink>
<ForceLoad>True</ForceLoad>
<Frameworks>SystemConfiguration UserNotifications WebKit CoreGraphics UIKit</Frameworks>
</NativeReference>
</ItemGroup>
</Target>
</Project>

0 comments on commit 63418a4

Please sign in to comment.