【发布时间】:2020-10-05 17:16:45
【问题描述】:
我下载后使用URLForResource查找按需资源,目前可以正常使用。
由于 Apple 在审核期间无法下载 ODR 的一些问题,我现在必须暂时将我的按需资源 AssetPacks 嵌入 App Bundle 中,将 XCode 中的“Embed Asset Packs In Product Bundle”从 false 更改为真的。
问题是,当我使用相同的 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) {
// ...
【问题讨论】:
-
不清楚问题是什么。按需资源不存储在你的 app bundle 中(你的 app bundle 是不可变的),目前还不清楚“将我的 OnDemandResources AssetPacks 临时嵌入到 App Bundle 中”是什么意思。
-
@matt 已编辑,现在应该更清楚了。谢谢
-
targetFolder是什么?为什么嵌入资产包会导致出现以前不存在的文件夹? -
另外,如果这是一个应用程序审查问题“由于 Apple 在审查期间无法下载 ODR 的一些问题”,我会担心问题是什么而不是试图规避它们暂时在测试期间(如大众汽车)。
-
另外,当您取消嵌入资产包时,您的计划是什么?您将不得不再次通过审核。
标签: ios objective-c swift xcode on-demand-resources