You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZXResult.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2012 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ZXResult.h"
  17. @interface ZXResult ()
  18. @property (nonatomic, strong) NSMutableDictionary *resultMetadata;
  19. @property (nonatomic, strong) NSMutableArray *resultPoints;
  20. @end
  21. @implementation ZXResult
  22. - (id)initWithText:(NSString *)text rawBytes:(ZXByteArray *)rawBytes resultPoints:(NSArray *)resultPoints format:(ZXBarcodeFormat)format {
  23. return [self initWithText:text rawBytes:rawBytes resultPoints:resultPoints format:format timestamp:CFAbsoluteTimeGetCurrent()];
  24. }
  25. - (id)initWithText:(NSString *)text rawBytes:(ZXByteArray *)rawBytes resultPoints:(NSArray *)resultPoints format:(ZXBarcodeFormat)format timestamp:(long)timestamp {
  26. if (self = [super init]) {
  27. _text = text;
  28. _rawBytes = rawBytes;
  29. _resultPoints = [resultPoints mutableCopy];
  30. _barcodeFormat = format;
  31. _resultMetadata = nil;
  32. _timestamp = timestamp;
  33. }
  34. return self;
  35. }
  36. + (id)resultWithText:(NSString *)text rawBytes:(ZXByteArray *)rawBytes resultPoints:(NSArray *)resultPoints format:(ZXBarcodeFormat)format {
  37. return [[self alloc] initWithText:text rawBytes:rawBytes resultPoints:resultPoints format:format];
  38. }
  39. + (id)resultWithText:(NSString *)text rawBytes:(ZXByteArray *)rawBytes resultPoints:(NSArray *)resultPoints format:(ZXBarcodeFormat)format timestamp:(long)timestamp {
  40. return [[self alloc] initWithText:text rawBytes:rawBytes resultPoints:resultPoints format:format timestamp:timestamp];
  41. }
  42. - (void)putMetadata:(ZXResultMetadataType)type value:(id)value {
  43. if (self.resultMetadata == nil) {
  44. self.resultMetadata = [NSMutableDictionary dictionary];
  45. }
  46. self.resultMetadata[@(type)] = value;
  47. }
  48. - (void)putAllMetadata:(NSMutableDictionary *)metadata {
  49. if (metadata != nil) {
  50. if (self.resultMetadata == nil) {
  51. self.resultMetadata = metadata;
  52. } else {
  53. [self.resultMetadata addEntriesFromDictionary:metadata];
  54. }
  55. }
  56. }
  57. - (void)addResultPoints:(NSArray *)newPoints {
  58. if (self.resultPoints == nil) {
  59. self.resultPoints = [newPoints mutableCopy];
  60. } else if (newPoints != nil && [newPoints count] > 0) {
  61. [self.resultPoints addObjectsFromArray:newPoints];
  62. }
  63. }
  64. - (NSString *)description {
  65. return self.text;
  66. }
  67. @end