You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

//
// SOS.m
// watch
//
// Created by xTT on 2017/7/17.
// Copyright © 2017xTT. All rights reserved.
//
#import "SOS.h"
#import "User.h"
@implementation SOS
+ (void)getSOSSuccess:(void (^)(NSMutableArray *arr))success
failure:(void (^)())failure{
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/sos"
objArr:@[cUser.cDevice]];
[xMyHttp URL:urlStr
method:@"GET" parameters:@{}
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
NSMutableArray *arr = [SOS mj_objectArrayWithKeyValuesArray:responseObject[@"sos"]];
success(arr);
}else{
failure();
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure();
}
}];
}
+ (void)saveSOS:(NSMutableArray *)sosArr
success:(void (^)())success
failure:(void (^)())failure{
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/sos"
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
NSMutableArray *ids = [NSMutableArray array];
NSMutableArray *phones = [NSMutableArray array];
[sosArr enumerateObjectsUsingBlock:^(SOS *obj, NSUInteger idx, BOOL * _Nonnull stop) {
[ids addObject:obj.id];
[phones addObject:obj.phone];
}];
[parameters setValue:[ids mj_JSONString] forKey:@"ids"];
[parameters setValue:[phones mj_JSONString] forKey:@"phones"];
[xMyHttp URL:urlStr
method:@"PATCH" parameters:parameters
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
success();
}else{
failure();
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure();
}
}];
}
@end