Results.Add(permission, await RequestLocationPermission(permission)) Results.Add(permission, await RequestContactsPermission()) Results.Add(permission, await RequestAVPermissionStatusAsync(AVMediaType.Video)) Results.Add(permission, await RequestEventPermission(EKEntityType.Event)) Well, let's look at the code: public async Task> RequestPermissionsAsync(params Permission permissions)
This fuzzy photo (sorry about that) shows that even though my code was only requesting one permission, all of the code was still there.
until I packaged up an app, extracted the dll from the final package and put it into dotPeek on Windows and found out that NOTHING was getting linked out: So, I turned on the and thought everything was going to be fine. This was because the library itself checks all sorts of different permissions and since I didn't optimize it for the linker, Apple was detecting usage of the APIs and started to require the ist to add permissions that weren't actually being used. When I started to look at my other cross-platform libraries I noticed that the PermissionsPlugin was starting to cause people some submission issues on iOS. This library was built and structured with the linker in mind with very little overlapping code, and each feature is implemented in it's own class. It means that if you only use the Compass then that will be the ONLY chunk of code that is included in the app. This is cool because you are telling the linker that you have done the work to test your library and want it to be treated as if it was part of Xamarin.iOS or Xamarin.Android.Ī great example of this is Xamarin.Essentials which is completely optimized with this property. This is where the attribute comes in to inform the linker to include this library in ALL linking modes. Sometimes it is really important that unused code in your library is properly removed. I like to always test my library in Link ALL Assemblies mode and if something goes wrong and gets removed then I slap this on the class.
The can be added to any class in your iOS or Android library and then the linker will ignore that class. There are instances where you are creating a library and always want to ensure that NOTHING is ever removed regardless of the linker setting. You never know when a developer may flip on Link All Assemblies or when the linker may get aggressive and link away some of your library. You can learn more about this on the iOS and Android documentation.įor library creators it is super important to understand how the linker works, and how you can optimize your libraries for app developers. linkskip= -linkskip= -linkskip= -linkskip= -linkskip=Samples
For instance if you are building an app with Xamarin.Forms you probably want to leave all of Xamarin.Forms in there so you could add some flags to iOS and Android: // iOS The linker is pretty customizable and you can tell it to ignore specific libraries in the project settings. The difference between the two in terms of application size is usually minimal and often when linking everything you can get in trouble as the linker can be aggressive and will remove more than needed, especially if you use reflection. I always recommend Link SDK Assemblies Only as it is the safest and easiest to understand. The other option is Link All Assemblies, which will look at every assembly and library that your app uses and attempt to link them. This will only look to link and remove libraries that ship with Xamarin.iOS and Xamarin.Android.
Linking for App Developersīefore I get to how to optimize libraries, let me go through when the linker actually kicks in and how app developers use it.įor the large majority of developers, all you need to know is turn on Link SDK Assemblies Only when your app is in Release (it is the default). The linker has specific implementations for both iOS and Android and is completely customizable. It should only be used in release mode as it takes extra time to compile your app, but means that your app will be smaller: It does all of the hard work for you, stripping out all unused code from libraries that you include in your apps. The Xamarin linker is one of the most important pieces of technology when building mobile apps, that no one knows exists.