您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ZXSMSParsedResult.m 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "ZXSMSParsedResult.h"
  17. @implementation ZXSMSParsedResult
  18. - (id)initWithNumber:(NSString *)number via:(NSString *)via subject:(NSString *)subject body:(NSString *)body {
  19. NSArray *numbers;
  20. if (number) {
  21. numbers = @[number];
  22. }
  23. NSArray *vias;
  24. if (via) {
  25. vias = @[via];
  26. }
  27. return [self initWithNumbers:numbers vias:vias subject:subject body:body];
  28. }
  29. - (id)initWithNumbers:(NSArray *)numbers vias:(NSArray *)vias subject:(NSString *)subject body:(NSString *)body {
  30. if (self = [super initWithType:kParsedResultTypeSMS]) {
  31. _numbers = numbers;
  32. _vias = vias;
  33. _subject = subject;
  34. _body = body;
  35. }
  36. return self;
  37. }
  38. + (id)smsParsedResultWithNumber:(NSString *)number via:(NSString *)via subject:(NSString *)subject body:(NSString *)body {
  39. return [[self alloc] initWithNumber:number via:via subject:subject body:body];
  40. }
  41. + (id)smsParsedResultWithNumbers:(NSArray *)numbers vias:(NSArray *)vias subject:(NSString *)subject body:(NSString *)body {
  42. return [[self alloc] initWithNumbers:numbers vias:vias subject:subject body:body];
  43. }
  44. - (NSString *)sMSURI {
  45. NSMutableString *result = [NSMutableString stringWithString:@"sms:"];
  46. BOOL first = YES;
  47. for (int i = 0; i < self.numbers.count; i++) {
  48. if (first) {
  49. first = NO;
  50. } else {
  51. [result appendString:@","];
  52. }
  53. [result appendString:self.numbers[i]];
  54. if (self.vias != nil && self.vias[i] != [NSNull null]) {
  55. [result appendString:@";via="];
  56. [result appendString:self.vias[i]];
  57. }
  58. }
  59. BOOL hasBody = self.body != nil;
  60. BOOL hasSubject = self.subject != nil;
  61. if (hasBody || hasSubject) {
  62. [result appendString:@"?"];
  63. if (hasBody) {
  64. [result appendString:@"body="];
  65. [result appendString:self.body];
  66. }
  67. if (hasSubject) {
  68. if (hasBody) {
  69. [result appendString:@"&"];
  70. }
  71. [result appendString:@"subject="];
  72. [result appendString:self.subject];
  73. }
  74. }
  75. return result;
  76. }
  77. - (NSString *)displayResult {
  78. NSMutableString *result = [NSMutableString stringWithCapacity:100];
  79. [ZXParsedResult maybeAppendArray:self.numbers result:result];
  80. [ZXParsedResult maybeAppend:self.subject result:result];
  81. [ZXParsedResult maybeAppend:self.body result:result];
  82. return result;
  83. }
  84. @end