diff --git a/yinmeng-ios/DingDangApp.xcodeproj/project.pbxproj b/yinmeng-ios/DingDangApp.xcodeproj/project.pbxproj index 3193050..1ebdc23 100644 --- a/yinmeng-ios/DingDangApp.xcodeproj/project.pbxproj +++ b/yinmeng-ios/DingDangApp.xcodeproj/project.pbxproj @@ -767,6 +767,9 @@ 8C2C3F542B2A41F5002C3C34 /* DDV2PhoneCodeVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2C3F532B2A41F5002C3C34 /* DDV2PhoneCodeVC.m */; }; 8C2C3F572B2A4350002C3C34 /* DDLoginSVGAView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2C3F562B2A4350002C3C34 /* DDLoginSVGAView.m */; }; 8C2C3F5A2B2A70F9002C3C34 /* DDLoginRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2C3F592B2A70F9002C3C34 /* DDLoginRequest.m */; }; + 8C2C3F612B2A9A3B002C3C34 /* DDGloabalConstant.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2C3F602B2A9A3B002C3C34 /* DDGloabalConstant.m */; }; + 8C2C3F662B2A9C26002C3C34 /* DDRegisterCustomDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2C3F652B2A9C26002C3C34 /* DDRegisterCustomDecoder.m */; }; + 8C2C3F6A2B2A9CFB002C3C34 /* DDCustomAttachmentModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2C3F692B2A9CFB002C3C34 /* DDCustomAttachmentModel.m */; }; 8CE493992B23F44800CA14D5 /* NSMutableDictionary+DDSafe.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CE493982B23F44800CA14D5 /* NSMutableDictionary+DDSafe.m */; }; 8CE4939C2B23F45C00CA14D5 /* NSArray+DDSafe.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CE4939B2B23F45C00CA14D5 /* NSArray+DDSafe.m */; }; 8CE493A02B23F5FA00CA14D5 /* DDUploadFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CE4939F2B23F5FA00CA14D5 /* DDUploadFile.m */; }; @@ -2196,6 +2199,12 @@ 8C2C3F582B2A70F9002C3C34 /* DDLoginRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DDLoginRequest.h; sourceTree = ""; }; 8C2C3F592B2A70F9002C3C34 /* DDLoginRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DDLoginRequest.m; sourceTree = ""; }; 8C2C3F5E2B2A886A002C3C34 /* DDV2RequestUrl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DDV2RequestUrl.h; sourceTree = ""; }; + 8C2C3F5F2B2A9A3B002C3C34 /* DDGloabalConstant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DDGloabalConstant.h; sourceTree = ""; }; + 8C2C3F602B2A9A3B002C3C34 /* DDGloabalConstant.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DDGloabalConstant.m; sourceTree = ""; }; + 8C2C3F642B2A9C26002C3C34 /* DDRegisterCustomDecoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DDRegisterCustomDecoder.h; sourceTree = ""; }; + 8C2C3F652B2A9C26002C3C34 /* DDRegisterCustomDecoder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DDRegisterCustomDecoder.m; sourceTree = ""; }; + 8C2C3F682B2A9CFB002C3C34 /* DDCustomAttachmentModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DDCustomAttachmentModel.h; sourceTree = ""; }; + 8C2C3F692B2A9CFB002C3C34 /* DDCustomAttachmentModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DDCustomAttachmentModel.m; sourceTree = ""; }; 8CAB97312B2259EA00ED8639 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 8CE493972B23F44800CA14D5 /* NSMutableDictionary+DDSafe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableDictionary+DDSafe.h"; sourceTree = ""; }; 8CE493982B23F44800CA14D5 /* NSMutableDictionary+DDSafe.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableDictionary+DDSafe.m"; sourceTree = ""; }; @@ -5497,6 +5506,8 @@ isa = PBXGroup; children = ( 23B2A8062B2843B6001C0913 /* DDMacroHeader.h */, + 8C2C3F5F2B2A9A3B002C3C34 /* DDGloabalConstant.h */, + 8C2C3F602B2A9A3B002C3C34 /* DDGloabalConstant.m */, ); path = DDGlobalManager; sourceTree = ""; @@ -5505,6 +5516,7 @@ isa = PBXGroup; children = ( 23B62C2E2B299E26005FD3DE /* DDDynamic */, + 8C2C3F622B2A9BEC002C3C34 /* DDNIM */, 23A7F7902B29551D00288CAE /* DDApplePay */, 23A7F7862B28795500288CAE /* DDHome */, 23A7F78A2B28795500288CAE /* DDMine */, @@ -5756,6 +5768,33 @@ path = Model; sourceTree = ""; }; + 8C2C3F622B2A9BEC002C3C34 /* DDNIM */ = { + isa = PBXGroup; + children = ( + 8C2C3F672B2A9CEC002C3C34 /* Model */, + 8C2C3F632B2A9C04002C3C34 /* Tool */, + ); + path = DDNIM; + sourceTree = ""; + }; + 8C2C3F632B2A9C04002C3C34 /* Tool */ = { + isa = PBXGroup; + children = ( + 8C2C3F642B2A9C26002C3C34 /* DDRegisterCustomDecoder.h */, + 8C2C3F652B2A9C26002C3C34 /* DDRegisterCustomDecoder.m */, + ); + path = Tool; + sourceTree = ""; + }; + 8C2C3F672B2A9CEC002C3C34 /* Model */ = { + isa = PBXGroup; + children = ( + 8C2C3F682B2A9CFB002C3C34 /* DDCustomAttachmentModel.h */, + 8C2C3F692B2A9CFB002C3C34 /* DDCustomAttachmentModel.m */, + ); + path = Model; + sourceTree = ""; + }; 8CE493952B23F2B400CA14D5 /* DDBaseTool */ = { isa = PBXGroup; children = ( @@ -6388,6 +6427,7 @@ 188EC0EC2A47CF3200060F03 /* DDMEmoticonCell.m in Sources */, 18660D4E2A2193C50032D0C9 /* NSDictionary+Custom.m in Sources */, 186EBFB72A402F33005623CC /* DynamicCommentViewController.m in Sources */, + 8C2C3F662B2A9C26002C3C34 /* DDRegisterCustomDecoder.m in Sources */, 188EC0E12A47CF3200060F03 /* SVGView.m in Sources */, 18660DCE2A21E54B0032D0C9 /* RoomMicroView.m in Sources */, 18B1EA252A26F31A00DDE889 /* DDDynamicDataTableViewCell.m in Sources */, @@ -6554,6 +6594,7 @@ 1867778B2A42D3D80096D802 /* RoomTypeCollectionViewCell.m in Sources */, 189956A22A21F804002ABEEB /* RoomMicroHeaderView.m in Sources */, 188CA97F2A501A6200DAFC86 /* DDV2HomeListVC.m in Sources */, + 8C2C3F6A2B2A9CFB002C3C34 /* DDCustomAttachmentModel.m in Sources */, 183864392A28A17B005BF235 /* ZLAlbumListController.m in Sources */, 186C9D062A29EE3500209BB5 /* ZLMediaProgressView.m in Sources */, 187AE10A2A493DFB00B427CB /* RoomBlackListView.m in Sources */, @@ -6625,6 +6666,7 @@ 18660D802A21947B0032D0C9 /* WLBaseTableViewCell.m in Sources */, 18660CBE2A21913E0032D0C9 /* WRNavigationBar.m in Sources */, 18C905082A233D5200F7CAFD /* XHPageControl.m in Sources */, + 8C2C3F612B2A9A3B002C3C34 /* DDGloabalConstant.m in Sources */, 188EC1402A47CF3300060F03 /* HXPhotoEditStickerTrashView.m in Sources */, 188EBF6A2A47CEA500060F03 /* DDMessageCell.m in Sources */, 188EBF6D2A47CEA500060F03 /* DDInteractiveMessageVC.m in Sources */, diff --git a/yinmeng-ios/DingDangApp.xcodeproj/xcshareddata/xcschemes/DingDangApp.xcscheme b/yinmeng-ios/DingDangApp.xcodeproj/xcshareddata/xcschemes/DingDangApp.xcscheme index f8380f6..d21fe79 100644 --- a/yinmeng-ios/DingDangApp.xcodeproj/xcshareddata/xcschemes/DingDangApp.xcscheme +++ b/yinmeng-ios/DingDangApp.xcodeproj/xcshareddata/xcschemes/DingDangApp.xcscheme @@ -1,7 +1,7 @@ + version = "1.8"> diff --git a/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+CYLTabBar.m b/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+CYLTabBar.m index cb60d73..0e0ca80 100644 --- a/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+CYLTabBar.m +++ b/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+CYLTabBar.m @@ -21,6 +21,8 @@ #import "AccountInfoStorage.h" #import "HttpRequestHelper.h" #import "DDLoginRequest.h" +/// Tool +#import @interface AppDelegate (CYLTabBar) @@ -56,6 +58,7 @@ NSArray *tickets = [data.data valueForKey:@"tickets"]; NSString *ticket = [tickets[0] valueForKey:@"ticket"]; [[AccountInfoStorage instance] saveTicket:ticket]; + [self loginNIM]; [self getUserInfo]; } failure:^(NSInteger resCode, NSString * _Nonnull message) { [ToolsObject addPopVieToText:[NSString stringWithFormat:@"加载页面%@失败,请重新登录",message]]; @@ -65,6 +68,31 @@ }]; } +- (void)loginNIM { + AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo]; + if (accountModel == nil) { + [self gotoWithLoginController]; + return; + } + + if ([NIMSDK sharedSDK].loginManager.isLogined) { + return; + } + + NIMAutoLoginData *data = [[NIMAutoLoginData alloc]init]; + data.account = accountModel.uid; + data.token = accountModel.netEaseToken; + data.forcedMode = NO; +// [[NIMSDK sharedSDK].loginManager autoLogin:data]; + [[NIMSDK sharedSDK].loginManager login:accountModel.uid token:accountModel.netEaseToken completion:^(NSError * _Nullable error) { + if (error) { + + } + + }]; + +} + - (void)getUserInfo { [DDLoginRequest DD_LoadRequestUserInfo:[[AccountInfoStorage instance] getUid] completed:^(UserInfoModel * _Nonnull userInfo) { if (userInfo == nil) { diff --git a/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+Other.m b/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+Other.m index 963b94a..063a6e1 100644 --- a/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+Other.m +++ b/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate+Other.m @@ -13,6 +13,9 @@ #import #import #import "DDV2LoginVC.h" +#import +#import "DDGloabalConstant.h" +#import "DDRegisterCustomDecoder.h" @interface AppDelegate (Other) @end @@ -41,8 +44,34 @@ didEndEditingNotificationName:YYTextViewTextDidEndEditingNotification]; [self initUMeng]; [self initShanyanSDK]; + [self initNIM]; [HCKeepBGRunManager shareManager]; } + +// 推荐在程序启动的时候初始化 NIMSDK +- (void)initNIM { + NSString *appKey = DD_Constant_KeyWithType(DD_Constant_KeyType_NetEase); + NIMSDKOption *option = [NIMSDKOption optionWithAppKey:appKey]; + option.apnsCername = DD_Constant_KeyWithType(DD_Constant_KeyType_APNSCer); + [[NIMSDK sharedSDK] registerWithOption:option]; + + // NIM SDK初始化 + [NIMCustomObject registerCustomDecoder:[[DDRegisterCustomDecoder alloc] init]]; + +#ifdef DEBUG + [NIMSDKConfig sharedConfig].enabledHttpsForInfo = NO; + [NIMSDKConfig sharedConfig].enabledHttpsForMessage = NO; +#endif + + if (@available(iOS 11.0, *)){ + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) { + }]; + } + [[UIApplication sharedApplication] registerForRemoteNotifications]; +} + + - (void)initUMeng { NSString * channel = @"App Store"; #ifdef DEBUG @@ -84,8 +113,7 @@ } }]; } -- (void)getLinkPath:(NSDictionary *)params -{ +- (void)getLinkPath:(NSDictionary *)params { UINavigationController *platformVc = (UINavigationController *)self.window.rootViewController; if (params.count > 0) { DDV2LoginVC *vc = platformVc.viewControllers[0]; diff --git a/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate.m b/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate.m index 7e16afd..e8b845f 100644 --- a/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate.m +++ b/yinmeng-ios/DingDangApp/AppDelegate/AppDelegate.m @@ -11,6 +11,7 @@ #import "AppDelegate+NetworkStatus.h" #import "AppDelegate+CYLTabBar.h" #import "AppDelegate+Other.h" +#import @interface AppDelegate () @@ -35,6 +36,15 @@ } +- (void)applicationDidEnterBackground:(UIApplication *)application { + NSInteger count = [NIMSDK sharedSDK].conversationManager.allUnreadCount; + [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count]; +} + +- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + // 上传devicetoken至云信服务器。 + [[NIMSDK sharedSDK] updateApnsToken:deviceToken]; +} + (AppDelegate* )getAppdelegate { return (AppDelegate*)[UIApplication sharedApplication].delegate; diff --git a/yinmeng-ios/DingDangApp/BsaseClass/Controllers/CustomTabbarController/WLCoustomTabBarController.m b/yinmeng-ios/DingDangApp/BsaseClass/Controllers/CustomTabbarController/WLCoustomTabBarController.m index af4bccd..fffeeb8 100644 --- a/yinmeng-ios/DingDangApp/BsaseClass/Controllers/CustomTabbarController/WLCoustomTabBarController.m +++ b/yinmeng-ios/DingDangApp/BsaseClass/Controllers/CustomTabbarController/WLCoustomTabBarController.m @@ -15,8 +15,12 @@ #import "DDV2HomePVC.h" #import "UITabBar+badge.h" #import "DDFMDBManager.h" +#import +#import "AccountInfoStorage.h" +#import "AccountModel.h" -@interface WLCoustomTabBarController () +@interface WLCoustomTabBarController () @end @@ -25,6 +29,12 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. + NSLog(@"云信登录是否成功:%ld",[NIMSDK sharedSDK].loginManager.isLogined) + + [[NIMSDK sharedSDK].loginManager addDelegate:self]; + [[NIMSDK sharedSDK].chatManager addDelegate:self]; + [[NIMSDK sharedSDK].systemNotificationManager addDelegate:self]; + [[NIMSDK sharedSDK].broadcastManager addDelegate:self]; //添加未读消息数量监听 [[DDMTool sharedTool] observationInform:self sel:@selector(messageUnreadNumber:) notificationName:[[DDMTool sharedTool]getinformType:(YVMessageNotice_MessageUnreadNumber)]]; @@ -264,14 +274,28 @@ } -/* - #pragma mark - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - // Get the new view controller using [segue destinationViewController]. - // Pass the selected object to the new view controller. - } - */ +#pragma mark - NIMLoginManagerDelegate +- (void)onAutoLoginFailed:(NSError *)error { + // 如果非上次登录设备 autoLogin 会返回 417 + if (error.code == 417) { +// @weakify(self); + AccountModel* accountModel = [AccountInfoStorage instance].getCurrentAccountInfo; + [[NIMSDK sharedSDK].loginManager login:accountModel.uid token:accountModel.netEaseToken completion:^(NSError * _Nullable error) { + if (error) { +// @strongify(self); + [ToolsObject loginOutJump]; +// [self.presenter logout]; + } + }]; + return; + } + [ToolsObject loginOutJump]; +// [self.presenter logout]; +} + +- (void)onLogin:(NIMLoginStep)step { + if (step != NIMLoginStepLoginOK) return; + // [self addMessageBadge]; +} @end diff --git a/yinmeng-ios/DingDangApp/BsaseClass/Tool/ToolsObject.m b/yinmeng-ios/DingDangApp/BsaseClass/Tool/ToolsObject.m index 4fd77e9..fc9a780 100644 --- a/yinmeng-ios/DingDangApp/BsaseClass/Tool/ToolsObject.m +++ b/yinmeng-ios/DingDangApp/BsaseClass/Tool/ToolsObject.m @@ -19,6 +19,7 @@ #import "SDImageCache.h" #import "RoomEditPassWordView.h" #import "AccountInfoStorage.h" +#import static NSString *SAVELOGIN = @"LOGINMODEL"; static NSString *SAVECITYINFO = @"CITYINFO"; static NSString *SAVELOGINVIDEO = @"LOGINVIDEO"; @@ -701,7 +702,7 @@ static NSString *SAVEROOMCONFIG = @"ROOMCONFIG"; - (void)jumpToRoomVC:(NSString *)room_id followUser:(RoomUserInfoModel *)followUser{ [ToolsObject ShowSVProgressHUD:@""]; AppDelegate *delegate = (AppDelegate*)kAppDelegate; - if([ToolsObject isBlankString:room_id].length ==0){ + if([ToolsObject isBlankString:room_id].length == 0 || room_id == nil){ [ToolsObject addPopVieToText:@"未找到房间ID"]; } //判断是否已进入房间 @@ -846,6 +847,9 @@ static NSString *SAVEROOMCONFIG = @"ROOMCONFIG"; [ToolsObject removeUserInfo]; [[AccountInfoStorage instance] saveTicket:nil]; [[AccountInfoStorage instance] saveAccountInfo:nil]; + if ([NIMSDK sharedSDK].loginManager.isLogined) { + [[NIMSDK sharedSDK].loginManager logout:nil]; + } [kUserDefaults removeObjectForKey:KYoungPasswordKey]; DDV2LoginVC *loginViewController = [[DDV2LoginVC alloc] init]; diff --git a/yinmeng-ios/DingDangApp/V2Versions/Home/DDV2HomeVC.m b/yinmeng-ios/DingDangApp/V2Versions/Home/DDV2HomeVC.m index 1e21e6b..f58909e 100644 --- a/yinmeng-ios/DingDangApp/V2Versions/Home/DDV2HomeVC.m +++ b/yinmeng-ios/DingDangApp/V2Versions/Home/DDV2HomeVC.m @@ -205,11 +205,11 @@ self.isClick = YES; if (self.isNoCollection) { DDRoomPartyModel *model = self.noDataArr[indexPath.item]; - [[ToolsObject shareTools] jumpToRoomVC:model.room_id followUser:[RoomUserInfoModel new]]; + [[ToolsObject shareTools] jumpToRoomVC:model.roomId followUser:[RoomUserInfoModel new]]; }else{ DDRoomPartyModel *model = self.dataArr[indexPath.item]; - [[ToolsObject shareTools] jumpToRoomVC:model.room_id followUser:[RoomUserInfoModel new]]; + [[ToolsObject shareTools] jumpToRoomVC:model.roomId followUser:[RoomUserInfoModel new]]; } WeakSelf(ws) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{ diff --git a/yinmeng-ios/DingDangApp/YingMeng/DDGlobalManager/DDGloabalConstant.h b/yinmeng-ios/DingDangApp/YingMeng/DDGlobalManager/DDGloabalConstant.h new file mode 100644 index 0000000..87dd261 --- /dev/null +++ b/yinmeng-ios/DingDangApp/YingMeng/DDGlobalManager/DDGloabalConstant.h @@ -0,0 +1,26 @@ +// +// DDGloabalConstant.h +// DingDangApp +// +// Created by 触海 on 2023/12/13. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, DDConstantKeyType) { + DD_Constant_KeyType_NetEase, ///云信的key + DD_Constant_KeyType_TRTC,///TRTC key + DD_Constant_KeyType_APNSCer,///推送证书的名字 +}; + +@interface DDGloabalConstant : NSObject + + +/// 获取当前项目中所用到的 type 所对应的 value 的值 type 类型 +NSString * const DD_Constant_KeyWithType(DDConstantKeyType type); + +@end + +NS_ASSUME_NONNULL_END diff --git a/yinmeng-ios/DingDangApp/YingMeng/DDGlobalManager/DDGloabalConstant.m b/yinmeng-ios/DingDangApp/YingMeng/DDGlobalManager/DDGloabalConstant.m new file mode 100644 index 0000000..690106a --- /dev/null +++ b/yinmeng-ios/DingDangApp/YingMeng/DDGlobalManager/DDGloabalConstant.m @@ -0,0 +1,37 @@ +// +// DDGloabalConstant.m +// DingDangApp +// +// Created by 触海 on 2023/12/13. +// + +#import "DDGloabalConstant.h" + +@implementation DDGloabalConstant + +NSString * const DD_Constant_KeyWithType(DDConstantKeyType type) { +BOOL isRelase = NO; +#ifdef DEBUG + isRelase = NO; +#else + isRelase = YES; +#endif + NSDictionary * dic = @{ + ///正式环境 + @(YES):@{ + @(DD_Constant_KeyType_TRTC) : @"1400798783", + @(DD_Constant_KeyType_NetEase) : @"5e76ec47632d86c30ce18eabfa332b6a", + @(DD_Constant_KeyType_APNSCer) : @"yinyouApnsRelease", + }, + ///测试环境 + @(NO):@{ + @(DD_Constant_KeyType_TRTC) : @"1400798783", + @(DD_Constant_KeyType_NetEase) : @"5e76ec47632d86c30ce18eabfa332b6a", + @(DD_Constant_KeyType_APNSCer) : @"yinyouApnsDebug", + } + }; + NSDictionary * enviroDic = [dic objectForKey:@(isRelase)]; + return [enviroDic objectForKey:@(type)]; +} + +@end diff --git a/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Model/DDCustomAttachmentModel.h b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Model/DDCustomAttachmentModel.h new file mode 100644 index 0000000..2b61483 --- /dev/null +++ b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Model/DDCustomAttachmentModel.h @@ -0,0 +1,19 @@ +// +// DDCustomAttachmentModel.h +// DingDangApp +// +// Created by 触海 on 2023/12/13. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface DDCustomAttachmentModel : NSObject +@property (nonatomic,assign) int first; +@property (nonatomic,assign) int second; +@property (nonatomic, strong) id data; +@end + +NS_ASSUME_NONNULL_END diff --git a/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Model/DDCustomAttachmentModel.m b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Model/DDCustomAttachmentModel.m new file mode 100644 index 0000000..801281d --- /dev/null +++ b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Model/DDCustomAttachmentModel.m @@ -0,0 +1,16 @@ +// +// DDCustomAttachmentModel.m +// DingDangApp +// +// Created by 触海 on 2023/12/13. +// + +#import "DDCustomAttachmentModel.h" +#import "NSObject+DDExtension.h" + +@implementation DDCustomAttachmentModel +- (NSString *)encodeAttachment { + return [self dd_toJSONString]; +} + +@end diff --git a/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Tool/DDRegisterCustomDecoder.h b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Tool/DDRegisterCustomDecoder.h new file mode 100644 index 0000000..ab3c592 --- /dev/null +++ b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Tool/DDRegisterCustomDecoder.h @@ -0,0 +1,17 @@ +// +// DDRegisterCustomDecoder.h +// DingDangApp +// +// Created by 触海 on 2023/12/13. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface DDRegisterCustomDecoder : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Tool/DDRegisterCustomDecoder.m b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Tool/DDRegisterCustomDecoder.m new file mode 100644 index 0000000..99c166f --- /dev/null +++ b/yinmeng-ios/DingDangApp/YingMeng/DDMain/DDNIM/Tool/DDRegisterCustomDecoder.m @@ -0,0 +1,54 @@ +// +// DDRegisterCustomDecoder.m +// DingDangApp +// +// Created by 触海 on 2023/12/13. +// + +#import "DDRegisterCustomDecoder.h" +#import "DDCustomAttachmentModel.h" + +@implementation DDRegisterCustomDecoder + +- (id)decodeAttachment:(NSString *)content { + id custom_attachment; + NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding]; + if (!data) { + return custom_attachment; + } + + NSDictionary *dict_json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + if ([dict_json isKindOfClass:[NSDictionary class]]) { + int first = [dict_json[@"first"] intValue]; + int second = [dict_json[@"second"] intValue]; + NSDictionary *data = dict_json[@"data"]; + if ([data isKindOfClass:[NSString class]]) { + data = [self dd_dictionaryWithJsonString:(NSString *)data]; + } + if ([data isKindOfClass:[NSDictionary class]]) { + DDCustomAttachmentModel *attachment = [[DDCustomAttachmentModel alloc] init]; + attachment.first = (short)first; + attachment.second = (short)second; + attachment.data = data; + return attachment; + } + } + return custom_attachment; +} + +//json格式字符串转字典: +- (NSDictionary *)dd_dictionaryWithJsonString:(NSString *)jsonString { + if (jsonString == nil) return nil; + + NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; + NSError *err; + NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData + options:NSJSONReadingMutableContainers + error:&err]; + + if(err) return nil; + return dic; + +} + +@end