Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Issues implementing DependencyService on iOS when it is defined in a library

$
0
0

I have the following structure:
1. PCL project that defines the DependencyService interface. Output is a library
2. iOS project that implements DependencyService. Output is a library
3. PCL project that uses a class that is implemented in 1. which calls the service.
4. iOS project that creates the app.

For some reason this works on Android but on iOS, the call to the iOS DependencyService returns null.

There is a lot of code associated with the issue. So here only the high-lights:
For 1.:
public interface INativeStyles
{

        StyleSupport.FontSizes GetAccessiblityFontSize();
    }
...
nativeFontSize = DependencyService.Get<INativeStyles>().GetAccessiblityFontSize();

For 2.:
[assembly: Xamarin.Forms.Dependency (typeof (OurLib.iOS.NativeStyles_iOS))]

namespace OurLib.iOS
{

    public class NativeStyles_iOS : INativeStyles
    {

        public NativeStyles_iOS() {}

        public StyleSupport.FontSizes GetAccessiblityFontSize()
        {
            StyleSupport.FontSizes commonSize = StyleSupport.FontSizes.FONT_SIZE_M;

            try {
                // Get native Accessiblity Font Size
                var nativeSize = UIApplication.SharedApplication.PreferredContentSizeCategory;

                // Translate to common size
                commonSize = TranslateToCommonStyle(nativeSize);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception " + ex.Message);
            }
            return commonSize;
        }   
    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>