Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ZXSMSTOMMSTOResultParser.m 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #import "ZXSMSTOMMSTOResultParser.h"
  18. #import "ZXSMSParsedResult.h"
  19. @implementation ZXSMSTOMMSTOResultParser
  20. - (ZXParsedResult *)parse:(ZXResult *)result {
  21. NSString *rawText = [ZXResultParser massagedText:result];
  22. if (!([rawText hasPrefix:@"smsto:"] || [rawText hasPrefix:@"SMSTO:"] || [rawText hasPrefix:@"mmsto:"] || [rawText hasPrefix:@"MMSTO:"])) {
  23. return nil;
  24. }
  25. // Thanks to dominik.wild for suggesting this enhancement to support
  26. // smsto:number:body URIs
  27. NSString *number = [rawText substringFromIndex:6];
  28. NSString *body = nil;
  29. NSUInteger bodyStart = [number rangeOfString:@":"].location;
  30. if (bodyStart != NSNotFound) {
  31. body = [number substringFromIndex:bodyStart + 1];
  32. number = [number substringToIndex:bodyStart];
  33. }
  34. return [ZXSMSParsedResult smsParsedResultWithNumber:number via:nil subject:nil body:body];
  35. }
  36. @end