【问题标题】:static void method not being called on iOS 8在 iOS 8 上未调用静态 void 方法
【发布时间】:2023-03-23 12:26:02
【问题描述】:

我有以下方法在 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)

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 雷达[609:76761] Accucary 65 2014-09-19 09:14:52.258 Mapa Radar[609:76761] SELECT * FROM Radares WHERE distance2(纬度,经度,-23.516678,-47.477784)

为什么在 iOS 8 上,我的表 Radares 没有被识别,但在 iOS 6 和 7 上它可以工作?

【问题讨论】:

  • 1) 检查sqlite3_create_function 的返回值,确保函数已创建。 2) 运行查询时是否到达while 循环的内部?
  • 该函数没有被创建,但仅在 iOS8 上。“static void distanceFunc”中的代码在 iOS8 上不运行。在调试模式下我检查了它..
  • sqlite3_create_function 的返回值是多少?
  • rmaddy 的意思是 sqlite3_create_function 有返回码!! 返回什么值? int sqlite3_create_function(... -- int 是返回码。您应该始终检查 SQLite 返回码。
  • 另外,你从 prepare 和 step 得到什么返回码?

标签: ios sqlite ios7 ios8 void


【解决方案1】:

问题是:

我从服务器下载基础并保存在 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];

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2011-07-21
    • 2019-06-29
    相关资源
    最近更新 更多