|
| 1 | +// |
| 2 | +// ApiIndices.m |
| 3 | +// flutter_qweather |
| 4 | +// |
| 5 | +// Created by CyJay on 2021/6/5. |
| 6 | +// |
| 7 | + |
| 8 | +#import "ApiIndices.h" |
| 9 | +#import "../DebugPrint/DebugPrint.h" |
| 10 | +@implementation ApiIndices |
| 11 | +/// 获取1天生活指数 |
| 12 | ++ (void) getIndices1Day:(id)param result:(FlutterResult)result{ |
| 13 | + [ApiIndices getIndices:@"getIndices1Day" param:param result:result]; |
| 14 | +} |
| 15 | +/// 获取3天生活指数 |
| 16 | ++ (void) getIndices3Day:(id)param result:(FlutterResult)result{ |
| 17 | + [ApiIndices getIndices:@"getIndices3Day" param:param result:result]; |
| 18 | +} |
| 19 | + |
| 20 | +/// 获取生活指数 |
| 21 | ++ (void) getIndices:(NSString*)name param:(id)param result:(FlutterResult)result{ |
| 22 | + NSDictionary *paramDic = param; |
| 23 | + QWeatherConfigInstance.location = paramDic[@"location"]; |
| 24 | + NSArray<NSString*> *indicesTypes = paramDic[@"indicesTypes"]; |
| 25 | + NSMutableArray<NSString*> *indicesTypesTmp = [NSMutableArray new]; |
| 26 | + for (int i = 0; i < indicesTypes.count; i++){ |
| 27 | + NSString *str = [indicesTypes objectAtIndex:i]; |
| 28 | + if ([str isEqualToString:@"SPT"]){ |
| 29 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_spt]]; |
| 30 | + } else if ([str isEqualToString:@"CW"]){ |
| 31 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_cw]]; |
| 32 | + } else if ([str isEqualToString:@"DRSG"]){ |
| 33 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_drsg]]; |
| 34 | + } else if ([str isEqualToString:@"FIS"]){ |
| 35 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_fis]]; |
| 36 | + } else if ([str isEqualToString:@"UV"]){ |
| 37 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_uv]]; |
| 38 | + } else if ([str isEqualToString:@"TRAV"]){ |
| 39 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_trav]]; |
| 40 | + } else if ([str isEqualToString:@"AG"]){ |
| 41 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ag]]; |
| 42 | + } else if ([str isEqualToString:@"COMF"]){ |
| 43 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_comf]]; |
| 44 | + } else if ([str isEqualToString:@"FLU"]){ |
| 45 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_flu]]; |
| 46 | + } else if ([str isEqualToString:@"AP"]){ |
| 47 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ap]]; |
| 48 | + } else if ([str isEqualToString:@"AC"]){ |
| 49 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ac]]; |
| 50 | + } else if ([str isEqualToString:@"GL"]){ |
| 51 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_gl]]; |
| 52 | + } else if ([str isEqualToString:@"MU"]){ |
| 53 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_mu]]; |
| 54 | + } else if ([str isEqualToString:@"DC"]){ |
| 55 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_dc]]; |
| 56 | + } else if ([str isEqualToString:@"PTEC"]){ |
| 57 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ptfc]]; |
| 58 | + } else if ([str isEqualToString:@"SPI"]){ |
| 59 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_spi]]; |
| 60 | + } else if ([str isEqualToString:@"SKI"]){ |
| 61 | + [indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ski]]; |
| 62 | + } else { |
| 63 | + indicesTypesTmp = [NSMutableArray arrayWithObject:INDICES_TYPESTRING[INDICES_TYPE_all]]; |
| 64 | + break; |
| 65 | + } |
| 66 | + } |
| 67 | + QWeatherConfigInstance.indices = indicesTypesTmp; |
| 68 | + INQUIRE_TYPE inquireType = INQUIRE_TYPE_INDICES_1D; |
| 69 | + if ([name isEqualToString:@"getIndices3Day"]){ |
| 70 | + inquireType = INQUIRE_TYPE_INDICES_3D; |
| 71 | + } |
| 72 | + [QWeatherConfigInstance weatherWithInquireType:inquireType WithSuccess:^(IndicesBaseClass *rep) { |
| 73 | + [DebugPrint print:[name stringByAppendingString:[@" WithSuccess: " stringByAppendingString:rep.description]]]; |
| 74 | + if (![rep.code isEqualToString:@"200"]){ |
| 75 | + result(NULL); |
| 76 | + return; |
| 77 | + } |
| 78 | + NSMutableArray<NSDictionary*> *dailyList = [NSMutableArray new]; |
| 79 | + for (IndicesDaily *one in rep.daily) { |
| 80 | + NSDictionary *oneIndicesDaily = @{@"date": one.date, @"type": one.type, @"name":one.name, |
| 81 | + @"level":one.level, @"category": one.category, @"text": one.text}; |
| 82 | + [dailyList addObject:oneIndicesDaily]; |
| 83 | + } |
| 84 | + NSDictionary *refer = @{@"licenseList": rep.refer.license, @"sourcesList": rep.refer.sources}; |
| 85 | + NSDictionary *basic = @{@"fxLink": rep.fxLink, @"updateTime": rep.updateTime}; |
| 86 | + NSMutableDictionary *dic = [NSMutableDictionary new]; |
| 87 | + [dic setValue:rep.code forKey:@"code"]; |
| 88 | + [dic setValue:refer forKey:@"refer"]; |
| 89 | + [dic setValue:basic forKey:@"basic"]; |
| 90 | + [dic setValue:dailyList forKey:@"dailyList"]; |
| 91 | + result(dic); |
| 92 | + } faileureForError:^(NSError *error) { |
| 93 | + [DebugPrint print:[name stringByAppendingString:[@" faileureForError: " stringByAppendingString:error.localizedDescription]]]; |
| 94 | + result(NULL); |
| 95 | + }]; |
| 96 | +} |
| 97 | +@end |
0 commit comments