LookinConnectionResponseAttachment.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // LookinConnectionResponse.m
  3. // Lookin
  4. //
  5. // Created by Li Kai on 2019/1/15.
  6. // https://lookin.work
  7. //
  8. #import "LookinConnectionResponseAttachment.h"
  9. #import "LookinDefines.h"
  10. @interface LookinConnectionResponseAttachment ()
  11. @end
  12. @implementation LookinConnectionResponseAttachment
  13. - (void)encodeWithCoder:(NSCoder *)aCoder {
  14. [super encodeWithCoder:aCoder];
  15. [aCoder encodeInt:self.lookinServerVersion forKey:@"lookinServerVersion"];
  16. [aCoder encodeObject:self.error forKey:@"error"];
  17. [aCoder encodeObject:@(self.dataTotalCount) forKey:@"dataTotalCount"];
  18. [aCoder encodeObject:@(self.currentDataCount) forKey:@"currentDataCount"];
  19. [aCoder encodeBool:self.lookinServerIsExprimental forKey:@"lookinServerIsExprimental"];
  20. [aCoder encodeBool:self.appIsInBackground forKey:@"appIsInBackground"];
  21. }
  22. - (instancetype)init {
  23. if (self = [super init]) {
  24. self.lookinServerVersion = LOOKIN_SERVER_VERSION;
  25. self.dataTotalCount = 0;
  26. self.lookinServerIsExprimental = LOOKIN_SERVER_IS_EXPERIMENTAL;
  27. }
  28. return self;
  29. }
  30. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  31. if (self = [super initWithCoder:aDecoder]) {
  32. self.lookinServerVersion = [aDecoder decodeIntForKey:@"lookinServerVersion"];
  33. self.lookinServerIsExprimental = [aDecoder decodeBoolForKey:@"lookinServerIsExprimental"];
  34. self.error = [aDecoder decodeObjectForKey:@"error"];
  35. self.dataTotalCount = [[aDecoder decodeObjectForKey:@"dataTotalCount"] unsignedIntegerValue];
  36. self.currentDataCount = [[aDecoder decodeObjectForKey:@"currentDataCount"] unsignedIntegerValue];
  37. self.appIsInBackground = [aDecoder decodeBoolForKey:@"appIsInBackground"];
  38. }
  39. return self;
  40. }
  41. + (BOOL)supportsSecureCoding {
  42. return YES;
  43. }
  44. + (instancetype)attachmentWithError:(NSError *)error {
  45. LookinConnectionResponseAttachment *attachment = [LookinConnectionResponseAttachment new];
  46. attachment.error = error;
  47. return attachment;
  48. }
  49. @end