Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS 8上未调用静态void方法_Ios_Sqlite_Ios7_Ios8_Void - Fatal编程技术网

在iOS 8上未调用静态void方法

在iOS 8上未调用静态void方法,ios,sqlite,ios7,ios8,void,Ios,Sqlite,Ios7,Ios8,Void,我在iOS6和iOS7上使用了以下方法 #import "MapaViewController.h" #import "sqlite3.h" #import "CelulaAlertas.h" #import "OBRadar.h" #import "OBDownloadBase.h" #define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180 static void distanceFunc(sqli

我在iOS6和iOS7上使用了以下方法

#import "MapaViewController.h"
#import "sqlite3.h"
#import "CelulaAlertas.h"  
#import "OBRadar.h"
#import "OBDownloadBase.h"

#define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180

static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
{
   // check that we have four arguments (lat1, lon1, lat2, lon2)
    assert(argc == 4);
// check that all four arguments are non-null
   if (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL || sqlite3_value_type(argv[2]) == SQLITE_NULL || sqlite3_value_type(argv[3]) == SQLITE_NULL) {
    sqlite3_result_null(context);
    return;
}
// get the four argument values
double lat1 = sqlite3_value_double(argv[0]);
double lon1 = sqlite3_value_double(argv[1]);
double lat2 = sqlite3_value_double(argv[2]);
double lon2 = sqlite3_value_double(argv[3]);
// convert lat1 and lat2 into radians now, to avoid doing it twice below
double lat1rad = DEG2RAD(lat1);
double lat2rad = DEG2RAD(lat2);
// apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately
// 6378.1 is the approximate radius of the earth in kilometres
sqlite3_result_double(context, acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) * 6378.1);
}

在我的初始方法中,我调用:

sqlite3_create_function(db, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);
在我的选择上:

NSString *qsql= [NSString stringWithFormat:@"SELECT * FROM Radares WHERE distance(Latitude, Longitude, %@, %@)<1 ORDER BY distance(Latitude, Longitude, %@, %@)",lat,longi,lat,longi];

NSLog(@"%@",qsql);

sqlite3_stmt *statement;
if (sqlite3_prepare_v2( db, [qsql UTF8String], -1,
                       &statement, nil) == SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
    {.....
NSString*qsql=[NSString stringWithFormat:@“从距离(纬度、经度、%@、%@)的雷达中选择*”问题是:

我从服务器下载数据库,并将其保存在Documents目录下的文件中。在iOS7之前,我用于创建de file path以保存数据库的方法是可以的,但显然在iOS8上不是。它保存的是一个空数据库

因此,我使用了另一种方法来创建文档路径:

NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//make a file name to write the data to using the documents directory:
NSMutableString *fileName = [NSMutableString stringWithFormat:@"%@/radares.db",
                             documentsDirectory];


NSLog(@"%@",fileName);

[_dados writeToFile:fileName atomically:YES];

1) 检查
sqlite3\u create\u function
的返回值,以确保该函数已创建。2)在运行查询时,是否已到达
循环的内部?该函数未创建,但仅在iOS8上。内部代码为“static void distance func”“没有在iOS8上运行..在调试模式下我检查了..sqlite3\u create\u函数的返回值是多少?
?rmaddy说的是sqlite3\u create\u函数有一个返回代码!!返回的值是什么???
int sqlite3\u create\u函数?”(…
--
int
是一个返回码。您应该始终检查SQLite返回码。另外,您从prepare和step中得到了什么返回码?