SocketMsgModel.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // SocketMsgModel.m
  3. // OneCable
  4. //
  5. // Created by KaRam Kim on 2017. 4. 20..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "SocketMsgModel.h"
  9. #define MSG_TYPE_KEY @"message_type"
  10. #define REQUEST_ID_KEY @"request_id"
  11. @implementation SocketRequestModel
  12. -(id)initWithMsgType:(NSString *)msgType
  13. {
  14. if (self = [super init]) {
  15. self.messageType = msgType;
  16. }
  17. return self;
  18. }
  19. //-(void)setRequestId:(int)requestId
  20. //{
  21. // NSLog(@"Request ID : %d", requestId);
  22. // self.requestId = [NSString stringWithFormat:@"%d", requestId];
  23. //}
  24. -(NSString *)getSendMessage
  25. {
  26. NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithDictionary:_requestMsg];
  27. info[MSG_TYPE_KEY] = self.messageType;
  28. info[REQUEST_ID_KEY] = self.requestId;
  29. NSError *error;
  30. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:info
  31. options:NSJSONWritingPrettyPrinted
  32. error:&error];
  33. NSString *result = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  34. if (!error)
  35. {
  36. NSLog(@"Got an error: %@", error);
  37. }
  38. return result;
  39. }
  40. @end