Xamarin iOS not finding path for sqlite database -


i working on ios app needs have simple sqlite db. in portable class library using xamarin. in code i'm attempting connection db, i'm not sure should placing database in project folder nor if #if __ ios__ working honestly, i'm using based on xamarin docs here: http://bit.ly/1mxsyey

public static sqliteconnection getconnection() {     #if __ios__         var sqlitefilename = "messages.db";         var docs = environment.getfolderpath(environment.specialfolder.personal);         var db = path.combine(docs, "..", "library", sqlitefilename);         return new sqliteconnection(db);     #endif     return null; } 

in pcl should using interfaces , dependency injection instead using if directives in shared solution.

eg. xamarin forms has dependency injection build in (but can use library):

pcl shared library:

public interface isqlite {     sqliteconnection getconnection(); } 

ios specific project:

[assembly: dependency (typeof (sqliteapple))] public class sqliteapple : isqlite  {     public sqlite.sqliteconnection getconnection ()     {         var sqlitefilename = "messages.db";         var docs = environment.getfolderpath(environment.specialfolder.personal);         var db = path.combine(docs, "..", "library", sqlitefilename);         return new sqliteconnection(db);     } } 

and use that:

var database = dependencyservice.get<isqlite>().getconnection(); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -