|
24 | 24 |
|
25 | 25 | @implementation FUIAuthUtils
|
26 | 26 |
|
27 |
| -+ (nullable NSBundle *)bundleNamed:(nullable NSString *)bundleName { |
28 |
| - NSBundle *frameworkBundle = nil; |
| 27 | ++ (NSBundle *)authUIBundle { |
| 28 | + return [self bundleNamed:FUIAuthBundleName |
| 29 | + inFrameworkBundle:[NSBundle bundleForClass:[self class]]]; |
| 30 | +} |
| 31 | + |
| 32 | ++ (nullable NSBundle *)bundleNamed:(nullable NSString *)bundleName |
| 33 | + inFrameworkBundle:(nullable NSBundle *)framework { |
| 34 | + NSBundle *returnBundle = nil; |
29 | 35 | if (!bundleName) {
|
30 | 36 | bundleName = FUIAuthBundleName;
|
31 | 37 | }
|
| 38 | + // Use the main bundle as a default if the framework wasn't provided. |
| 39 | + NSBundle *frameworkBundle = framework; |
| 40 | + if (frameworkBundle == nil) { |
| 41 | + // If frameworkBundle is unspecified, assume main bundle/static linking. |
| 42 | + frameworkBundle = [NSBundle mainBundle]; |
| 43 | + } |
| 44 | + // If using static frameworks, the bundle will be included directly in the main |
| 45 | + // bundle. |
32 | 46 | NSString *path = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"bundle"];
|
| 47 | + |
| 48 | + // Otherwise, check the appropriate framework bundle. |
33 | 49 | if (!path) {
|
34 |
| - // Check framework resources if bundle isn't present in main bundle. |
35 |
| - path = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"framework"]; |
| 50 | + path = [frameworkBundle pathForResource:bundleName ofType:@"bundle"]; |
36 | 51 | }
|
37 |
| - frameworkBundle = [NSBundle bundleWithPath:path]; |
38 |
| - if (!frameworkBundle) { |
39 |
| - frameworkBundle = [NSBundle bundleForClass:[self class]]; |
| 52 | + if (!path) { |
| 53 | + NSLog(@"Warning: Unable to find bundle %@ in framework %@.", bundleName, framework); |
| 54 | + // Fall back on the root module. |
| 55 | + return frameworkBundle; |
40 | 56 | }
|
41 |
| - return frameworkBundle; |
| 57 | + returnBundle = [NSBundle bundleWithPath:path]; |
| 58 | + return returnBundle; |
42 | 59 | }
|
43 | 60 |
|
44 | 61 | + (nullable UIImage *)imageNamed:(NSString *)name fromBundle:(nullable NSBundle *)bundle {
|
45 | 62 | if (!bundle) {
|
46 |
| - bundle = [self bundleNamed:nil]; |
| 63 | + bundle = [self authUIBundle]; |
47 | 64 | }
|
48 | 65 | NSString *path = [bundle pathForResource:name ofType:@"png"];
|
49 | 66 | if (!path) {
|
50 | 67 | NSLog(@"Warning: Unable to find asset %@ in bundle %@.", name, bundle);
|
51 | 68 | }
|
52 |
| - return [UIImage imageWithContentsOfFile:path]; |
53 |
| -} |
54 |
| - |
55 |
| -+ (nullable UIImage *)imageNamed:(NSString *)name fromBundleNameOrNil:(nullable NSString *)bundleNameOrNil { |
56 |
| - NSString *path = [[FUIAuthUtils bundleNamed:bundleNameOrNil] pathForResource:name ofType:@"png"]; |
57 |
| - if (!path) { |
58 |
| - NSLog(@"Warning: Unable to find asset %@ in bundle named %@.", name, bundleNameOrNil); |
| 69 | + if (@available(iOS 13.0, *)) { |
| 70 | + return [UIImage imageNamed:name inBundle:bundle withConfiguration:nil]; |
| 71 | + } else { |
| 72 | + return [UIImage imageWithContentsOfFile:path]; |
59 | 73 | }
|
60 |
| - return [UIImage imageWithContentsOfFile:path]; |
61 | 74 | }
|
62 | 75 |
|
63 | 76 | @end
|
0 commit comments