Xamarin shared code issue with dependency service

I have a project set up so that I can have a different styled for each of our clients
e.g.

  • PCL Project (shared code, Forms, etc)
  • Android.Shared (shared resources/localisations for the android apps/platform specific code)
  • Android.Client1Theme (custom resources (logos, colors, etc) for Client1)
  • Android.Client2Theme (custom resources (logos, colors, etc) for Client2)
  • iOS.Shared (shared resources/localisations for the android apps/platform specific code)
  • iOS.Client1Theme (custom resources (logos, colors, etc) for Client1)
  • iOS.Client2Theme (custom resources (logos, colors, etc) for Client2)

I have android working correctly by setting the dependencies for the Client1.droid project however the same setup for iOS isn't working and i get an issue with the dependency service getting a null reference when looking for my interface.

iOS.Shared dependencies =

  • PCL Project

iOS.Client1Theme dependencies =

  • PCL Project
  • iOS.Shared

PCL Code
DependencyService.Get<ISystemFunctions>().ToggleTorch();

Shared iOS project code

[assembly: Dependency(typeof(SystemFunctions_iOS))]
namespace ShareApp.iOS.iOS_Interfaces
{
    public class SystemFunctions_iOS : ISystemFunctions
    {        
        public SystemFunctions_iOS()
        {   }

        public void ToggleTorch()
        {
            var device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
            if (device == null)
                return;

            device.LockForConfiguration(out NSError error);
            if (error != null)
            {
                device.UnlockForConfiguration();
                return;
            }
            else
            {
                device.TorchMode = device.TorchMode == AVCaptureTorchMode.On ? AVCaptureTorchMode.Off : AVCaptureTorchMode.On;
                device.UnlockForConfiguration();
            }
        }
    }
}
Sign In or Register to comment.