自定义函数SQLite与Mono

Dea*_*ind 6 c# sql sqlite mono xamarin.ios

有没有办法使用Mono添加SQLite自定义函数?(Mono.Data.Sqlite)

我尝试添加距离函数,返回两个地理位置之间的距离

    [SqliteFunctionAttribute(Name = "distance", Arguments = 4, FuncType = FunctionType.Scalar)]
    class SqliteDistance : SqliteFunction
    {
        public override object Invoke(object[] args)
        {
            double radius = 6367;
            double lat1 = System.Convert.ToDouble(args[0]);
            double lng1 = System.Convert.ToDouble(args[1]);
            double lat2 = System.Convert.ToDouble(args[2]);
            double lng2 = System.Convert.ToDouble(args[3]);

            return radius * 2 * Math.Asin( Math.Min(1, Math.Sqrt( ( Math.Pow(Math.Sin((lat2* (Math.PI / 180) - lat1 * (Math.PI / 180) ) / 2.0), 2.0) + Math.Cos(lat1* (Math.PI / 180)) * Math.Cos(lat2* (Math.PI / 180)) * Math.Pow(Math.Sin(( lng2* (Math.PI / 180)-lng1* (Math.PI / 180)) / 2.0), 2.0) ) ) ) ); 
        }
    }
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:

尝试使用-aot-only运行JIT编译方法'(包装器本机到托管)Mono.Data.Sqlite.SqliteFunction:ScalarCallback(intptr,int,intptr)'.有关更多信息,请参见http://docs.xamarin.com/ios/about/limitations.

lup*_*pus 7

查看错误报告的页面的Reverse Callbacks段落:实际上,您需要将MonoPInvokeCallbackAttribute属性应用于该方法(并且需要将其设置为静态).

这是对iOS设备的限制,因为它们不支持JIT编译器.