c# - Xamarin Dependency Service Issue -
in xamarin forms have solution this:
solution |- libraries | |- iinterface.cs | |- etc. | |- libraries.ios | |- interface.cs | |- etc. | |- forms.app | |- app.cs | |- etc. | |- forms.app.ios | |- etc.
- forms.app.ios references libraries.ios
- forms.app references libraries
- libraries.ios references libraries
- forms.app.ios references forms.app
iinterface.cs
namespace { public interface iinterface { void function (); } }
interface.cs
[assembly: xamarin.forms.dependency(typeof(a.interface))] namespace { public class interface : iinterface { public void function () { return; } } }
app.cs
namespace { public class app { public static page getmainpage () { var inter = dependencyservice.get<iinterface> (); // null. return new contentpage { content = new label { text = "hello, forms!", verticaloptions = layoutoptions.centerandexpand, horizontaloptions = layoutoptions.centerandexpand, }, }; } } }
how can make dependency service locate interface implementation? need have them in separate project because need same implementations in different projects.
adding bit more information. seems bug related linking in library defines dependency service described here.
i solved issue instantiating ios implementation of dependency service manually.
in ios project in appdelegate.cs, finishedlaunching method, create object of ios dependency service implementation, e.g.
var obj = new company.project.ios.nativeimplementation_ios ();
that worked me.
Comments
Post a Comment