我们正在使用AFHTTPSessionManager调用API Web服务, 但是问题是,当我们调用一个API时,它会调用2-3次以上,这对我们的服务器来说是一个大问题(例如,我们希望向该API托管位置的服务器发送5个请求,但是我们会收到超过15个或20个API服务器上的请求),这是一个很大的挑战,这将使我们的服务器承受高负载, 一次调用API时如何处理一次调用!
非常重要:我们发现该应用程序在“开发模式”中时并未发送重复的请求,但是Live应用程序(在应用商店中构建)存在此问题,即“ BUILD LIVE”是什么问题“与“开发模式构建”是如此不同吗?
我们需要同时选中获取和发布方法
我们也找到了此链接,尚未测试: https://github.com/Foreverland/AFHTTPSessionManager-AFUniqueGET
+ (void) onGetLastMeasurement:(const CUIViewController*) mVCPage type:
(int)type
{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSDictionary *dictParam = @{@"apiKey":API_NOR_APIKEY,
@"secretKey":API_NOR_SECRETKEY,
@"email":g_strEmail,
@"password":g_strPassword};
NSString *strURL = [NSString stringWithFormat:@"%@%@", API_URL_BASE,
API_URL_GETLASTMEASUREMENT];
[manager GET:strURL parameters:dictParam progress:nil
success:^(NSURLSessionTask *task, id responseObject)
{
if ([responseObject objectForKey:@"maintenanceMode"])
{
g_strMaintainance = [responseObject objectForKey:@"message"];
[CGlobal goMaintainance:mVCPage];
return;
}
BOOL bStatus = [[responseObject objectForKey:@"status"] boolValue];
NSString *message = [responseObject objectForKey:@"message"];
if(bStatus == true)
{
NSString* unitLength = [responseObject objectForKey:@"unitLength"];
NSString* unitWeight = [responseObject objectForKey:@"unitWeight"];
for (int i = 0; i < g_arrWUnitValue.count; i++)
{
if ([unitWeight isEqualToString:g_arrWUnitValue[i]])
{
g_pUserModel.pBodyMeasurementModel.nWUnit = i;
break;
}
}
for (int i = 0; i < g_arrLUnitValue.count; i++)
{
if ([unitLength isEqualToString:g_arrLUnitValue[i]])
{
g_pUserModel.pBodyMeasurementModel.nLUnit = i;
break;
}
}
NSDictionary *lastMeasurement = [responseObject objectForKey:@"lastMeasurement"];
g_pUserModel.pBodyMeasurementModel.fWeight = [[lastMeasurement objectForKey:@"weight"] floatValue];
g_pUserModel.pBodyMeasurementModel.fHeight = [[lastMeasurement objectForKey:@"height"] floatValue];
g_pUserModel.pBodyMeasurementModel.fChest = [[lastMeasurement objectForKey:@"chest"] floatValue];
g_pUserModel.pBodyMeasurementModel.fHips = [[lastMeasurement objectForKey:@"hips"] floatValue];
g_pUserModel.pBodyMeasurementModel.fThigh = [[lastMeasurement objectForKey:@"thigh"] floatValue];
g_pUserModel.pBodyMeasurementModel.fUpperarm = [[lastMeasurement objectForKey:@"upperArm"] floatValue];
g_pUserModel.pBodyMeasurementModel.fWaist = [[lastMeasurement objectForKey:@"waist"] floatValue];
g_pUserModel.pBodyMeasurementModel.strDisplayName = [lastMeasurement objectForKey:@"displayname"];
g_pUserModel.pBodyMeasurementModel.strCreationDate = [lastMeasurement objectForKey:@"creationDate"];
g_pUserModel.pBodyMeasurementModel.strModifiedDate = [lastMeasurement objectForKey:@"modifiedDate"];
if (mVCPage != nil)
[mVCPage onAPISuccess:type result:message];
}
else
{
if (mVCPage != nil)
[mVCPage onAPISuccess:type result:message];
}
} failure:^(NSURLSessionTask * _Nullable task, NSError * _Nonnull error)
{
if (mVCPage != nil)
[mVCPage onAPIFail:type result:strURL];
}];
}
已受到赞赏... 谢谢