Няма описание

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2019 Google
  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 "FIRInstanceIDVersionUtilities.h"
  17. // Convert the macro to a string
  18. #define STR(x) STR_EXPAND(x)
  19. #define STR_EXPAND(x) #x
  20. static NSString *const kSemanticVersioningSeparator = @".";
  21. static NSString *const kBetaVersionPrefix = @"-beta";
  22. static NSString *libraryVersion;
  23. static int majorVersion;
  24. static int minorVersion;
  25. static int patchVersion;
  26. static int betaVersion;
  27. void FIRInstanceIDParseCurrentLibraryVersion() {
  28. static NSArray *allVersions;
  29. static dispatch_once_t onceToken;
  30. dispatch_once(&onceToken, ^{
  31. NSMutableString *daylightVersion =
  32. [NSMutableString stringWithUTF8String:STR(FIRInstanceID_LIB_VERSION)];
  33. // Parse versions
  34. // major, minor, patch[-beta#]
  35. allVersions = [daylightVersion componentsSeparatedByString:kSemanticVersioningSeparator];
  36. if (allVersions.count == 3) {
  37. majorVersion = [allVersions[0] intValue];
  38. minorVersion = [allVersions[1] intValue];
  39. // Parse patch and beta versions
  40. NSArray *patchAndBetaVersion =
  41. [allVersions[2] componentsSeparatedByString:kBetaVersionPrefix];
  42. if (patchAndBetaVersion.count == 2) {
  43. patchVersion = [patchAndBetaVersion[0] intValue];
  44. betaVersion = [patchAndBetaVersion[1] intValue];
  45. } else if (patchAndBetaVersion.count == 1) {
  46. patchVersion = [patchAndBetaVersion[0] intValue];
  47. }
  48. }
  49. // Copy library version
  50. libraryVersion = [daylightVersion copy];
  51. });
  52. }
  53. NSString *FIRInstanceIDCurrentLibraryVersion() {
  54. FIRInstanceIDParseCurrentLibraryVersion();
  55. return libraryVersion;
  56. }
  57. int FIRInstanceIDCurrentLibraryVersionMajor() {
  58. FIRInstanceIDParseCurrentLibraryVersion();
  59. return majorVersion;
  60. }
  61. int FIRInstanceIDCurrentLibraryVersionMinor() {
  62. FIRInstanceIDParseCurrentLibraryVersion();
  63. return minorVersion;
  64. }
  65. int FIRInstanceIDCurrentLibraryVersionPatch() {
  66. FIRInstanceIDParseCurrentLibraryVersion();
  67. return patchVersion;
  68. }
  69. BOOL FIRInstanceIDCurrentLibraryVersionIsBeta() {
  70. FIRInstanceIDParseCurrentLibraryVersion();
  71. return betaVersion > 0;
  72. }