TUIConfig.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // TUIConfig.m
  3. // TUIKit
  4. //
  5. // Created by kennethmiao on 2018/11/5.
  6. // Copyright © 2018 Tencent. All rights reserved.
  7. //
  8. #import "TUIConfig.h"
  9. #import "TUICommonModel.h"
  10. #import "TUIDefine.h"
  11. #import "TUILogin.h"
  12. #import "TUIThemeManager.h"
  13. @interface TUIConfig ()
  14. @property(nonatomic, strong) UIImage *defaultGroupAvatarImage_Public;
  15. @property(nonatomic, strong) UIImage *defaultGroupAvatarImage_Meeting;
  16. @property(nonatomic, strong) UIImage *defaultGroupAvatarImage_AVChatRoom;
  17. @property(nonatomic, strong) UIImage *defaultGroupAvatarImage_Community;
  18. @end
  19. @implementation TUIConfig
  20. - (id)init {
  21. self = [super init];
  22. if (self) {
  23. _avatarCornerRadius = 5.f;
  24. _defaultAvatarImage = TUICoreBundleThemeImage(@"default_c2c_head_img", @"default_c2c_head");
  25. _defaultGroupAvatarImage = TUICoreBundleThemeImage(@"default_group_head_img", @"default_group_head");
  26. _defaultGroupAvatarImage_Public = TUICoreBundleThemeImage(@"default_group_head_public_img", @"default_group_head_public");
  27. _defaultGroupAvatarImage_Meeting = TUICoreBundleThemeImage(@"default_group_head_meeting_img", @"default_group_head_meeting");
  28. _defaultGroupAvatarImage_AVChatRoom = TUICoreBundleThemeImage(@"default_group_head_avchatroom_img", @"default_group_head_avchatRoom");
  29. _defaultGroupAvatarImage_Community = TUICoreBundleThemeImage(@"", @"default_group_head_community");
  30. _isExcludedFromUnreadCount = NO;
  31. _isExcludedFromLastMessage = NO;
  32. _enableToast = YES;
  33. _displayOnlineStatusIcon = NO;
  34. _enableGroupGridAvatar = YES;
  35. [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onChangeTheme) name:TUIDidApplyingThemeChangedNotfication object:nil];
  36. }
  37. return self;
  38. }
  39. + (id)defaultConfig {
  40. static dispatch_once_t onceToken;
  41. static TUIConfig *config;
  42. dispatch_once(&onceToken, ^{
  43. config = [[TUIConfig alloc] init];
  44. });
  45. return config;
  46. }
  47. - (void)onChangeTheme {
  48. self.defaultAvatarImage = TUICoreBundleThemeImage(@"default_c2c_head_img", @"default_c2c_head");
  49. self.defaultGroupAvatarImage = TUICoreBundleThemeImage(@"default_group_head_img", @"default_group_head");
  50. self.defaultGroupAvatarImage_Public = TUICoreBundleThemeImage(@"default_group_head_public_img", @"default_group_head_public");
  51. self.defaultGroupAvatarImage_Meeting = TUICoreBundleThemeImage(@"default_group_head_meeting_img", @"default_group_head_meeting");
  52. self.defaultGroupAvatarImage_AVChatRoom = TUICoreBundleThemeImage(@"default_group_head_avchatroom_img", @"default_group_head_avchatroom");
  53. self.defaultGroupAvatarImage_Community = TUICoreBundleThemeImage(@"default_group_head_community_img", @"default_group_head_community");
  54. }
  55. - (UIImage *)getGroupAvatarImageByGroupType:(NSString *)groupType {
  56. if ([groupType isEqualToString:GroupType_Work]) {
  57. return self.defaultGroupAvatarImage;
  58. } else if ([groupType isEqualToString:GroupType_Public]) {
  59. return self.defaultGroupAvatarImage_Public;
  60. } else if ([groupType isEqualToString:GroupType_Meeting]) {
  61. return self.defaultGroupAvatarImage_Meeting;
  62. } else if ([groupType isEqualToString:GroupType_AVChatRoom]) {
  63. return self.defaultGroupAvatarImage_AVChatRoom;
  64. } else if ([groupType isEqualToString:GroupType_Community]) {
  65. return self.defaultGroupAvatarImage_Community;
  66. } else {
  67. return self.defaultGroupAvatarImage;
  68. }
  69. }
  70. #pragma mark - Sence
  71. - (void)setSceneOptimizParams:(NSString *)path {
  72. NSURL *url = [NSURL URLWithString:@"https://demos.trtc.tencent-cloud.com/prod/base/v1/events/stat"];
  73. NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
  74. req.HTTPMethod = @"POST";
  75. NSDictionary *msgData =
  76. @{@"sdkappid" : @([TUILogin getSdkAppID]), @"bundleId" : NSBundle.mainBundle.bundleIdentifier ?: @"", @"package" : @"", @"component" : path};
  77. NSString* userId =[TUILogin getUserID];
  78. NSDictionary *param = @{@"userid" : (userId?:@""), @"event" : @"useScenario", @"msg" : msgData};
  79. NSData *data = [NSJSONSerialization dataWithJSONObject:param options:NSJSONWritingPrettyPrinted error:nil];
  80. if (!data) {
  81. return;
  82. }
  83. req.HTTPBody = data;
  84. NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
  85. config.HTTPAdditionalHeaders = @{@"api-key" : @"API_KEY", @"Content-Type" : @"application/json"};
  86. NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
  87. [[session dataTaskWithRequest:req
  88. completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
  89. if (data) {
  90. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  91. long code = [dic[@"errorCode"] longValue];
  92. if (code == 0) {
  93. NSLog(@"scene param [%@] success", path);
  94. } else {
  95. NSString *msg = dic[@"errorMessage"];
  96. NSLog(@"scene param [%@] failed: [%ld] %@", path, code, msg);
  97. }
  98. } else {
  99. NSLog(@"scene param [%@] error: res data nil", path);
  100. }
  101. }] resume];
  102. }
  103. @end