Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 55f63d3

Browse files
author
auto-submit[bot]
committed
Revert "[ios] Fix app extension not able to find assets from unloaded bundle (#46283)"
This reverts commit 8225b56.
1 parent 9d28c72 commit 55f63d3

File tree

32 files changed

+16
-1163
lines changed

32 files changed

+16
-1163
lines changed

shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
FLUTTER_ASSERT_ARC
1010

1111
const NSString* kDefaultAssetPath = @"Frameworks/App.framework/flutter_assets";
12-
static NSString* GetFlutterAssetPathFromBundle(NSBundle* bundle);
1312

1413
NSBundle* FLTFrameworkBundleInternal(NSString* flutterFrameworkBundleID, NSURL* searchURL) {
1514
NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager
@@ -30,7 +29,7 @@
3029
}
3130

3231
NSBundle* FLTGetApplicationBundle() {
33-
NSBundle* mainBundle = NSBundle.mainBundle;
32+
NSBundle* mainBundle = [NSBundle mainBundle];
3433
// App extension bundle is in <AppName>.app/PlugIns/Extension.appex.
3534
if ([mainBundle.bundleURL.pathExtension isEqualToString:@"appex"]) {
3635
// Up two levels.
@@ -49,7 +48,7 @@
4948
flutterFrameworkBundle = [NSBundle bundleWithIdentifier:flutterFrameworkBundleID];
5049
}
5150
if (flutterFrameworkBundle == nil) {
52-
flutterFrameworkBundle = NSBundle.mainBundle;
51+
flutterFrameworkBundle = [NSBundle mainBundle];
5352
}
5453
return flutterFrameworkBundle;
5554
}
@@ -59,23 +58,13 @@
5958
}
6059

6160
NSString* FLTAssetsPathFromBundle(NSBundle* bundle) {
62-
NSString* flutterAssetsPath = GetFlutterAssetPathFromBundle(bundle);
63-
if (flutterAssetsPath.length == 0) {
64-
flutterAssetsPath = GetFlutterAssetPathFromBundle(NSBundle.mainBundle);
65-
}
66-
return flutterAssetsPath;
67-
}
68-
69-
static NSString* GetFlutterAssetPathFromBundle(NSBundle* bundle) {
7061
NSString* flutterAssetsPath = FLTAssetPath(bundle);
7162
// Use the raw path solution so that asset path can be returned from unloaded bundles.
7263
// See https://github.com/flutter/engine/pull/46073
73-
NSString* assetsPath = [bundle pathForResource:flutterAssetsPath ofType:nil];
64+
NSString* assetsPath = [bundle pathForResource:flutterAssetsPath ofType:@""];
65+
7466
if (assetsPath.length == 0) {
75-
// In app extension, using full relative path (kDefaultAssetPath)
76-
// returns nil when the app bundle is not loaded. Try to use
77-
// the sub folder name, which can successfully return a valid path.
78-
assetsPath = [bundle pathForResource:@"flutter_assets" ofType:nil];
67+
assetsPath = [[NSBundle mainBundle] pathForResource:flutterAssetsPath ofType:@""];
7968
}
8069
return assetsPath;
8170
}

shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ - (void)testFLTAssetsURLFromBundle {
9393
id mockBundle = OCMClassMock([NSBundle class]);
9494
OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets");
9595
NSString* resultAssetsPath = @"path/to/foo/assets";
96-
OCMStub([mockBundle pathForResource:@"foo/assets" ofType:nil]).andReturn(resultAssetsPath);
96+
OCMStub([mockBundle pathForResource:@"foo/assets" ofType:@""]).andReturn(resultAssetsPath);
9797
NSString* path = FLTAssetsPathFromBundle(mockBundle);
9898
XCTAssertEqualObjects(path, @"path/to/foo/assets");
9999
}
@@ -102,9 +102,9 @@ - (void)testFLTAssetsURLFromBundle {
102102
id mockBundle = OCMClassMock([NSBundle class]);
103103
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
104104
NSString* resultAssetsPath = @"path/to/foo/assets";
105-
OCMStub([mockBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:nil])
105+
OCMStub([mockBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""])
106106
.andReturn(nil);
107-
OCMStub([mockMainBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:nil])
107+
OCMStub([mockMainBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""])
108108
.andReturn(resultAssetsPath);
109109
NSString* path = FLTAssetsPathFromBundle(mockBundle);
110110
XCTAssertEqualObjects(path, @"path/to/foo/assets");

0 commit comments

Comments
 (0)