LookinConnectionResponseAttachment.m 1.8 KB

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