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.

57 lines
1.8 KiB

6 years ago
  1. // Copyright 2017 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "Private/FIRBundleUtil.h"
  15. @implementation FIRBundleUtil
  16. + (NSArray *)relevantBundles {
  17. return @[ [NSBundle mainBundle], [NSBundle bundleForClass:[self class]] ];
  18. }
  19. + (NSString *)optionsDictionaryPathWithResourceName:(NSString *)resourceName
  20. andFileType:(NSString *)fileType
  21. inBundles:(NSArray *)bundles {
  22. // Loop through all bundles to find the config dict.
  23. for (NSBundle *bundle in bundles) {
  24. NSString *path = [bundle pathForResource:resourceName ofType:fileType];
  25. // Use the first one we find.
  26. if (path) {
  27. return path;
  28. }
  29. }
  30. return nil;
  31. }
  32. + (NSArray *)relevantURLSchemes {
  33. NSMutableArray *result = [[NSMutableArray alloc] init];
  34. for (NSBundle *bundle in [[self class] relevantBundles]) {
  35. NSArray *urlTypes = [bundle objectForInfoDictionaryKey:@"CFBundleURLTypes"];
  36. for (NSDictionary *urlType in urlTypes) {
  37. [result addObjectsFromArray:urlType[@"CFBundleURLSchemes"]];
  38. }
  39. }
  40. return result;
  41. }
  42. + (BOOL)hasBundleIdentifier:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
  43. for (NSBundle *bundle in bundles) {
  44. if ([bundle.bundleIdentifier isEqualToString:bundleIdentifier]) {
  45. return YES;
  46. }
  47. }
  48. return NO;
  49. }
  50. @end