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.
 
 
 
 

89 lines
2.9 KiB

//
// CourseGroup.m
// tongxin
//
// Created by ecell on 2021/11/26.
// Copyright © 2021 xTT. All rights reserved.
//
#import "CourseSchedule.h"
#import "User.h"
#import "Device.h"
@implementation CourseSchedule
-(void)saveToUserDefaults:(CourseSchedule *)schedule {
[[NSUserDefaults standardUserDefaults] setObject:schedule forKey:schedule.imei];
}
-(CourseSchedule *)getFromUserDefaults:(NSString *)imei {
return [[NSUserDefaults standardUserDefaults] objectForKey:imei];
}
-(void)save:(NSString *)timetable schedule:(NSString *)schedule success:(void (^)(void))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_SCHEDULE
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:timetable forKey:@"timetable"];
[parameter setValue:schedule forKey:@"schedule"];
[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 (^)(CourseSchedule *model))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_SCHEDULE
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) {
CourseSchedule *model = [[CourseSchedule alloc] init];
model.timetable = [responseObject[@"timetable"] stringValue];
model.schedule = [responseObject[@"schedule"] stringValue];
success(model);
} 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