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.
372 lines
12 KiB
372 lines
12 KiB
// |
|
// Circle.m |
|
// myWatch |
|
// |
|
// Created by xTT on 15/10/30. |
|
// Copyright © 2015年 xTT. All rights reserved. |
|
// |
|
|
|
#import "Circle.h" |
|
#import "myHttp.h" |
|
|
|
#import "CJFileUtility.h" |
|
|
|
#import <AVFoundation/AVFoundation.h> |
|
#import <Photos/Photos.h> |
|
|
|
|
|
#import "User.h" |
|
#import "Device.h" |
|
//#import <MessageDisplayKit/XHMessage.h> |
|
//#import <MessageDisplayKit/XHMessageVideoConverPhotoFactory.h> |
|
|
|
|
|
@implementation Circle |
|
|
|
- (baseModel *)getObjWithID:(NSString *)sender{ |
|
User *user = [self getUserWithUserID:sender]; |
|
Device *device = [self getDeviceWithIMEI:sender]; |
|
if (user) { |
|
return (baseModel *)user; |
|
}else if(device){ |
|
return (baseModel *)device; |
|
} |
|
return nil; |
|
} |
|
|
|
- (User *)getUserWithUserID:(NSString *)userID{ |
|
__block User *user = nil; |
|
[_members enumerateObjectsUsingBlock:^(NSDictionary * dic, NSUInteger idx, BOOL * _Nonnull stop) { |
|
User *obj = [User yy_modelWithJSON:dic]; |
|
if ([obj.openid isEqualToString:userID]) { |
|
user = obj; |
|
*stop = YES; |
|
} |
|
}]; |
|
return user; |
|
} |
|
|
|
//- (void)setDevices:(NSMutableArray *)devices{ |
|
// |
|
//} |
|
|
|
- (Device *)getDeviceWithIMEI:(NSString *)IMEI{ |
|
__block Device *device = nil; |
|
[cUser.myDevices enumerateObjectsUsingBlock:^(Device * obj, NSUInteger idx, BOOL * _Nonnull stop) { |
|
if ([obj.imei isEqualToString:IMEI]) { |
|
device = obj; |
|
*stop = YES; |
|
} |
|
}]; |
|
return device; |
|
} |
|
|
|
|
|
|
|
#pragma 获取圈详情 |
|
- (void)getCircleInfoSuccess:(void (^)())success |
|
failure:(void (^)())failure{ |
|
NSString *urlStr = [MyHttp getURL:HTTP_CHATGROUPS__ |
|
objArr:@[self]]; |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"GET" parameters:@{} |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
[self mj_setKeyValues:responseObject]; |
|
[User saveToFile]; |
|
success(); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
} showHUD:NO]; |
|
} |
|
|
|
#pragma 获取圈邀请码 |
|
- (void)getCircleInviteTokenSuccess:(void (^)(id responseObject))success |
|
failure:(void (^)())failure{ |
|
NSString *urlStr = [MyHttp getURL:HTTP_CHATGROUPS__INVITETOKEN |
|
objArr:@[self]]; |
|
|
|
NSMutableDictionary *param = [NSMutableDictionary dictionary]; |
|
[param setValue:TargetName forKey:@"channel"]; |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"GET" parameters:param |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
|
|
#pragma 获取信息(群聊) |
|
- (void)getCircleMessageWithParameters:(id)parameters |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure |
|
{ |
|
NSString *urlStr = [MyHttp getURL:HTTP_CHATGROUPS__MESSAGE |
|
objArr:@[self]]; |
|
|
|
NSLog(@"get msg url = %@", urlStr); |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"GET" parameters:parameters |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
|
|
NSLog(@"error = %@", error); |
|
|
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
#pragma 获取信息(单聊) |
|
- (void)getCircleSingleMessageWithImei:(NSString *)imei |
|
Parameters:(id)parameters |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure |
|
{ |
|
|
|
NSString *urlStr = [NSString stringWithFormat:@"getway/single/%@/message",imei]; |
|
|
|
NSLog(@"get msg url = %@", urlStr); |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"GET" parameters:parameters |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
|
|
NSLog(@"error = %@", error); |
|
|
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
|
|
#pragma 举报信息 |
|
- (void)reportCircleMessageWithParameters:(id)parameters |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure { |
|
|
|
NSString *urlStr = [MyHttp getURL:HTTP_REPORT__MESSAGE |
|
objArr:@[cUser]]; |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"POST" parameters:parameters |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
|
|
} |
|
|
|
#pragma 发送信息(群聊) |
|
- (void)sendCircleMessageWithParameters:(id)parameters |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure{ |
|
|
|
NSString *urlStr = [MyHttp getURL:HTTP_CHATGROUPS__MESSAGE |
|
objArr:@[self]]; |
|
|
|
|
|
NSData *data = parameters[@"content"]; |
|
[xMyHttp URL:urlStr method:@"POST" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData){ |
|
if ([parameters[@"type"] isEqualToNumber:@(2)]) |
|
{//图片 |
|
[formData appendPartWithFileData:data |
|
name:@"content" |
|
fileName:@"image.jpg" |
|
mimeType:@"image/jpeg"]; |
|
} |
|
else if ([parameters[@"type"] isEqualToNumber:@(3)]) |
|
{ |
|
[formData appendPartWithFileData:data |
|
name:@"content" |
|
fileName:@"voice" |
|
mimeType:@"amr"]; |
|
} |
|
|
|
}success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
|
|
} |
|
|
|
#pragma 发送信息(单聊) |
|
- (void)sendCircleMessageWithImei:(NSString *)imei |
|
Parameters:(id)parameters |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure{ |
|
|
|
|
|
NSString *urlStr = [NSString stringWithFormat:@"getway/single/%@/message",imei]; |
|
|
|
|
|
NSData *data = parameters[@"content"]; |
|
[xMyHttp URL:urlStr |
|
method:@"POST" parameters:parameters |
|
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) |
|
{ |
|
if ([parameters[@"type"] isEqualToNumber:@(2)]) {//图片 |
|
[formData appendPartWithFileData:data |
|
name:@"content" |
|
fileName:@"image.jpg" |
|
mimeType:@"image/jpeg"]; |
|
}else if ([parameters[@"type"] isEqualToNumber:@(3)]){ |
|
[formData appendPartWithFileData:data |
|
name:@"content" |
|
fileName:@"voice" |
|
mimeType:@"amr"]; |
|
} |
|
|
|
} |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
|
|
} |
|
|
|
#pragma 清除聊天消息(群聊) |
|
- (void)deleteCircleMessageWithParameters:(id)parameters |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure{ |
|
NSString *urlStr = [MyHttp getURL:HTTP_CHATGROUPS__MESSAGE |
|
objArr:@[self]]; |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"DELETE" parameters:parameters |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
#pragma 清除聊天消息(单聊聊) |
|
- (void)deleteSingleMessage:(NSString *)imei |
|
success:(void (^)(id responseObject))success |
|
failure:(void (^)())failure |
|
{ |
|
NSString *urlStr = [NSString stringWithFormat:@"getway/single/%@/message",imei]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:cUser.openid forKey:@"openid"]; |
|
[parameters setValue:cUser.accesstoken forKey:@"token"]; |
|
|
|
[xMyHttp URL:urlStr |
|
method:@"DELETE" parameters:parameters |
|
success:^(NSURLSessionDataTask *task, id responseObject) |
|
{ |
|
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { |
|
success(responseObject); |
|
}else{ |
|
failure(); |
|
} |
|
} failure:^(NSURLSessionDataTask *task, NSError *error) { |
|
if (failure) { |
|
failure(); |
|
} |
|
}]; |
|
} |
|
|
|
+ (UIAlertController *)getCameraSheetCamera:(void (^)())camera |
|
photoLibrary:(void (^)())photoLibrary{ |
|
if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusDenied){ |
|
[UICommon MessageErrorText:NSLocalizedStringFromTable(@"请在iOS设备的 设置-隐私-相机 中允许访问相机。", @"Localization", @"")]; |
|
}else if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusDenied){ |
|
[UICommon MessageErrorText:NSLocalizedStringFromTable(@"请在iOS设备的 设置-隐私-照片 中允许访问照片。", @"Localization", @"")]; |
|
}else{ |
|
UIAlertController *sheet = [UIAlertController alertControllerWithTitle:@"修改头像" |
|
message:nil |
|
preferredStyle:UIAlertControllerStyleActionSheet]; |
|
|
|
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"拍照", @"Localization", @"") |
|
style:UIAlertActionStyleDefault |
|
handler:^(UIAlertAction *action) |
|
{ |
|
camera(); |
|
}]; |
|
|
|
UIAlertAction *libraryAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"从相册选择", @"Localization", @"") |
|
style:UIAlertActionStyleDefault |
|
handler:^(UIAlertAction *action) |
|
{ |
|
photoLibrary(); |
|
}]; |
|
|
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" |
|
style:UIAlertActionStyleCancel |
|
handler:^(UIAlertAction * _Nonnull action) |
|
{}]; |
|
|
|
[sheet addAction:cameraAction]; |
|
[sheet addAction:libraryAction]; |
|
[sheet addAction:cancelAction]; |
|
return sheet; |
|
} |
|
return nil; |
|
} |
|
|
|
@end
|
|
|