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.

120 lines
3.9 KiB

//
// WhiteContactModel.m
// tongxin
//
// Created by ecell on 2021/10/19.
// Copyright © 2021 xTT. All rights reserved.
//
#import "WhiteContactModel.h"
#import "Device.h"
#import "User.h"
@implementation WhiteContactModel
-(void)save:(NSMutableDictionary *)parameter success:(void (^)(void))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = [MyHttp getURL:HTTP_HHTWHITE__CONTACT
objArr:@[cUser.cDevice]];
[xMyHttp URL:urlStr
method:@"POST" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == 0) {
success();
} else {
if (failure) {
NSString *domain = @"com.zuoyebang.iot.watch";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
-(void)query:(void (^)(NSMutableArray *arr))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = [MyHttp getURL:HTTP_WHITE__CONTACT
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
[xMyHttp URL:urlStr
method:@"GET" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == 0) {
NSMutableArray *arr = [WhiteContactModel mj_objectArrayWithKeyValuesArray:responseObject[@"whiteContacts"]];
success(arr);
} else {
if (failure) {
NSString *domain = @"com.zuoyebang.iot.watch";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
-(void)deleteModel:(NSArray *)modelArr success:(void (^)(void))success failure:(void (^)(NSError *error))failure
{
NSString *urlStr = [MyHttp getURL:HTTP_HHTWHITE__CONTACT
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
NSMutableArray *nameArr = [NSMutableArray new];
NSMutableArray *phoneArr = [NSMutableArray new];
NSMutableArray *IdArr = [NSMutableArray new];
for (WhiteContactModel *model in modelArr)
{
[nameArr addObject:model.name];
[phoneArr addObject:model.phone];
[IdArr addObject:model.id];
}
[parameter setValue:[nameArr componentsJoinedByString:@"_"] forKey:@"name"];
[parameter setValue:[phoneArr componentsJoinedByString:@"_"] forKey:@"phone"];
[parameter setValue:[IdArr componentsJoinedByString:@"_"] forKey:@"id"];
[xMyHttp URL:urlStr
method:@"DELETE" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == 0) {
success();
} else {
if (failure) {
NSString *domain = @"com.zuoyebang.iot.watch";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end