Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
15
#import "FirebaseCore/Sources/FIRBundleUtil.h"
16
 
17
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
18
 
19
@implementation FIRBundleUtil
20
 
21
+ (NSArray *)relevantBundles {
22
  return @[ [NSBundle mainBundle], [NSBundle bundleForClass:[self class]] ];
23
}
24
 
25
+ (NSString *)optionsDictionaryPathWithResourceName:(NSString *)resourceName
26
                                        andFileType:(NSString *)fileType
27
                                          inBundles:(NSArray *)bundles {
28
  // Loop through all bundles to find the config dict.
29
  for (NSBundle *bundle in bundles) {
30
    NSString *path = [bundle pathForResource:resourceName ofType:fileType];
31
    // Use the first one we find.
32
    if (path) {
33
      return path;
34
    }
35
  }
36
  return nil;
37
}
38
 
39
+ (NSArray *)relevantURLSchemes {
40
  NSMutableArray *result = [[NSMutableArray alloc] init];
41
  for (NSBundle *bundle in [[self class] relevantBundles]) {
42
    NSArray *urlTypes = [bundle objectForInfoDictionaryKey:@"CFBundleURLTypes"];
43
    for (NSDictionary *urlType in urlTypes) {
44
      [result addObjectsFromArray:urlType[@"CFBundleURLSchemes"]];
45
    }
46
  }
47
  return result;
48
}
49
 
50
+ (BOOL)hasBundleIdentifierPrefix:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
51
  for (NSBundle *bundle in bundles) {
52
    if ([bundle.bundleIdentifier isEqualToString:bundleIdentifier]) {
53
      return YES;
54
    }
55
 
56
    if ([GULAppEnvironmentUtil isAppExtension]) {
57
      // A developer could be using the same `FIROptions` for both their app and extension. Since
58
      // extensions have a suffix added to the bundleID, we consider a matching prefix as valid.
59
      NSString *appBundleIDFromExtension =
60
          [self bundleIdentifierByRemovingLastPartFrom:bundle.bundleIdentifier];
61
      if ([appBundleIDFromExtension isEqualToString:bundleIdentifier]) {
62
        return YES;
63
      }
64
    }
65
  }
66
  return NO;
67
}
68
 
69
+ (NSString *)bundleIdentifierByRemovingLastPartFrom:(NSString *)bundleIdentifier {
70
  NSString *bundleIDComponentsSeparator = @".";
71
 
72
  NSMutableArray<NSString *> *bundleIDComponents =
73
      [[bundleIdentifier componentsSeparatedByString:bundleIDComponentsSeparator] mutableCopy];
74
  [bundleIDComponents removeLastObject];
75
 
76
  return [bundleIDComponents componentsJoinedByString:bundleIDComponentsSeparator];
77
}
78
 
79
@end