FIRBundleUtil.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. + (NSSet *)relevantBundleIdentifiers {
  43. NSMutableSet *result = [[NSMutableSet alloc] init];
  44. for (NSBundle *bundle in [[self class] relevantBundles]) {
  45. [result addObject:[bundle bundleIdentifier]];
  46. }
  47. return result;
  48. }
  49. + (BOOL)hasBundleIdentifier:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
  50. for (NSBundle *bundle in bundles) {
  51. if ([bundle.bundleIdentifier isEqualToString:bundleIdentifier]) {
  52. return YES;
  53. }
  54. }
  55. return NO;
  56. }
  57. @end