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.
130 lines
3.8 KiB
130 lines
3.8 KiB
// |
|
// VoiceAlarm.m |
|
// myWear |
|
// |
|
// Created by xTT on 2017/3/4. |
|
// Copyright © 2017年 xTT. All rights reserved. |
|
// |
|
|
|
#import "VoiceAlarm.h" |
|
#import "User.h" |
|
|
|
#import "CJFileUtility.h" |
|
#import "VoiceConverter.h" |
|
|
|
@implementation VoiceAlarm |
|
@synthesize status = _status; |
|
|
|
|
|
+ (void)getObjsSuccess:(void (^)(NSMutableArray *arr))success |
|
failure:(void (^)(NSError *error))failure{ |
|
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/voiceAlarm" |
|
objArr:@[cUser.cDevice]]; |
|
[xMyHttp URL:urlStr |
|
method:@"GET" parameters:@{} |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
NSMutableArray *arr = [VoiceAlarm mj_objectArrayWithKeyValuesArray:responseObject[@"voiceAlarms"]]; |
|
success(arr); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(error); |
|
} |
|
}]; |
|
} |
|
|
|
- (void)saveSuccess:(void (^)())success |
|
failure:(void (^)())failure{ |
|
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/voiceAlarm" |
|
objArr:@[cUser.cDevice]]; |
|
NSString *method = @"POST"; |
|
if (self.id.length > 0) { |
|
method = @"PATCH"; |
|
} |
|
[self wavToAmr:self.voicePath]; |
|
|
|
NSMutableDictionary *parameters = [self mj_keyValues]; |
|
[parameters removeObjectForKey:@"content"]; |
|
|
|
[xMyHttp URL:urlStr method:method parameters:parameters |
|
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) |
|
{ |
|
if (self.voicePath) { |
|
NSString *voicePath = [CJFileUtility changeFileExt:self.voicePath ext:@"amr"]; |
|
NSData *data = [NSData dataWithContentsOfFile:voicePath]; |
|
[formData appendPartWithFileData:data |
|
name:@"content" |
|
fileName:@"voice" |
|
mimeType:@"amr"]; |
|
} |
|
} success:^(NSURLSessionDataTask *task, id responseObject) { |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
- (void)deleteSuccess:(void (^)())success |
|
failure:(void (^)())failure{ |
|
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/voiceAlarm" |
|
objArr:@[cUser.cDevice]]; |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"DELETE" parameters:@{@"id":self.id} |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
|
|
- (void)setDefaultValue{ |
|
_week = @"1111100"; |
|
_time = @"08:00"; |
|
_text = @"闹钟"; |
|
} |
|
|
|
- (void)setVoiceURL:(NSString *)voiceURL{ |
|
_voiceURL = voiceURL; |
|
if (_voicePath) { |
|
NSString *fileName = [NSString stringWithFormat:@"%@.wav",voiceURL]; |
|
NSString *wavPath = [CJFileUtility documentsPathSubDir:@"msg_audio" andFile:fileName]; |
|
[CJFileUtility moveFile:[CJFileUtility changeFileExt:_voicePath ext:@"wav"] |
|
to:wavPath]; |
|
} |
|
} |
|
|
|
|
|
- (NSNumber *)status{ |
|
if (!_status) { |
|
return @(YES); |
|
} |
|
return _status; |
|
} |
|
|
|
|
|
- (void)wavToAmr:(NSString *)path { |
|
//转格式 |
|
if ([CJFileUtility fileExists:path]) { |
|
NSString *armPath = [CJFileUtility changeFileExt:path ext:@"amr"]; |
|
[VoiceConverter wavToAmr:path amrSavePath:armPath]; |
|
} |
|
} |
|
|
|
@end
|
|
|