我有以下方法在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)
{.....
仅在iOS8上没有调用“distanceFunc”方法。有人可以帮我理解为什么吗?
我在sqlite中获得了两个不同的错误代码,在iOS 7和iOS 8中运行相同的代码:
ios7
2014-09-19 09:18:08.841 Mapa Radar [511:60b]数据库返回错误0:没有错误 2014-09-19 09:18:08.841 Mapa Radar [511:60b]数据库返回错误0:没有错误 2014-09-19 09:18:08.974 Mapa Radar [511:60b] Accucary 5 2014-09-19 09:18:08.975 Mapa Radar [511:60b] SELECT * FROM Radares WHERE distance2(纬度,经度,-23.111100,-46.849126)&lt; 1 ORDER BY distance2(纬度,经度,-23.111100,-46.849126 ) 2014-09-19 09:18:08.975 Mapa Radar [511:60b]数据库返回错误0:没有错误
iOS8上
2014-09-19 09:14:51.631 Mapa Radar [609:76761]数据库返回错误0:没有错误 2014-09-19 09:14:51.633 Mapa Radar [609:76761]数据库返回错误0:没有错误 2014-09-19 09:14:52.252 Mapa Radar [609:76761] Accucary 65 2014-09-19 09:14:52.258 Mapa Radar [609:76761] SELECT * FROM Radares WHERE distance2(纬度,经度,-23.516678,-47.477784)&lt; 1 ORDER BY distance2(纬度,经度,-23.516678,-47.477784 ) 2014-09-19 09:14:52.259 Mapa Radar [609:76761]数据库返回错误0:没有错误 2014-09-19 09:14:52.261 Mapa Radar [609:76761]数据库返回错误1:没有这样的表:Radares
为什么在iOS 8上,我的桌子Radares没有被识别,但在iOS 6和7上它可以工作?
答案 0 :(得分:0)
问题是:
我从服务器下载基础并保存在Documents目录中的文件中。直到iOS7,我用来创建de文件路径来保存基础的方法还可以,但显然在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];