我在下载后使用URLForResource来查找按需资源,它目前可以正常工作。
由于 Apple 在审核期间无法下载 ODR 的一些问题,我现在必须暂时将我的 On-Demand Resources AssetPacks 嵌入到 App Bundle 中,将 XCode 中的“Embed Asset Packs In Product Bundle”从 false 更改为 true。
问题是,当我使用相同的 URLForResource 方法后,它现在返回 null。
NSURL *myDirectoryURL = [[NSBundle mainBundle] URLForResource:targetFolder withExtension:@""];
由于它们成为产品包的一部分,我不应该以这种方式找到它们吗?
更新: 来自非 iOS 开发人员的一些(丑陋的)工作代码在 Cordova 插件上工作.. :)
NSLog(@"[odr] calling nsbrr conditionallyBeginAccessingResourcesWithCompletionHandler..");
@try
{
[odrRequest conditionallyBeginAccessingResourcesWithCompletionHandler:^(BOOL resourcesAvailable) {
if (resourcesAvailable) {
NSLog(@"[odr] already available (in-bundle) / downloaded.");
@try
{
NSURL *myDirectoryURL = [[NSBundle mainBundle] URLForResource:targetFolder withExtension:@""];
NSLog(@"[odr] Target directory URL: '%@'", myDirectoryURL);
NSString *res = myDirectoryURL.absoluteString;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:res];
NSLog(@"[odr] path found, returning it in callback: '%@'", res);
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@catch(id anException) {
NSString *errMsg = @"Error in path detection or calling callback (in already-downl-odr handler): ";
errMsg = [errMsg stringByAppendingString:anException];
NSLog(@"[odr] Exception: '%@'", errMsg);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errMsg];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
} else {
NSLog(@"[odr] Starting to load (in-bundle) / download..");
@try
{
[odrRequest beginAccessingResourcesWithCompletionHandler:^(NSError * _Nullable error) {
if (error == nil) {
NSLog(@"[odr] File load / download success.");
@try
{
NSURL *myDirectoryURL = [[NSBundle mainBundle] URLForResource:targetFolder withExtension:@""];
NSLog(@"[odr] Target directory URL: '%@'", myDirectoryURL);
NSString *res = myDirectoryURL.absoluteString;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:res];
NSLog(@"[odr] path found, returning it in callback: '%@'", res);
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@catch(id anException) {
// ...