我在iPad应用程序中遇到了一种非常奇怪的行为。我创建了几个捆绑包,应用程序下载它们并将它们保存到文档目录。
我有一个自定义捆绑管理器,我可以像这样加载捆绑包。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *bundlePath;
if (![bundleName hasSuffix:@".bundle"]) {
bundlePath = [documentsDirectory stringByAppendingFormat:@"/%@.bundle", bundleName];
} else {
bundlePath = [documentsDirectory stringByAppendingFormat:@"/%@", bundleName];
}
NSBundle *bundle = nil;
NSError *error = nil;
bundle = [[NSBundle alloc] initWithPath:bundlePath];
if (!bundle) {
return nil;
}
[bundle loadAndReturnError:&error];
在调试模式下,所有代码都像魅力一样。捆绑包已加载,内容可在应用程序中使用。捆绑包含图像和笔尖,没有代码。在捆绑构建设置中,我将 COMBINE_HIDPI_IMAGES 设置为否,这样图像就不会合并为tiff图像。捆绑包也不包含任何代码。
那么问题是什么。好吧,当没有调试(没有连接到Xcode)启动应用程序时,应用程序崩溃并生成此错误消息。 [bundle loadAndReturnError:& error] 是代码崩溃的地方。
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 dyld 0x2fe8e2d8 strcmp + 0
1 dyld 0x2fe83aac ImageLoaderMachO::parseLoadCmds() + 56
2 dyld 0x2fe88d30 ImageLoaderMachOCompressed::instantiateFromFile(char const*, int, unsigned char const*, unsigned long long, unsigned long long, stat const&, unsigned int, unsigned int, linkedit_data_command const*, ImageLoader::LinkContext const&) + 296
3 dyld 0x2fe839c6 ImageLoaderMachO::instantiateFromFile(char const*, int, unsigned char const*, unsigned long long, unsigned long long, stat const&, ImageLoader::LinkContext const&) + 222
4 dyld 0x2fe7b0d4 dyld::loadPhase6(int, stat const&, char const*, dyld::LoadContext const&) + 664
5 dyld 0x2fe7e774 dyld::loadPhase5stat(char const*, dyld::LoadContext const&, stat*, int*, bool*, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 428
6 dyld 0x2fe7e498 dyld::loadPhase5(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 248
7 dyld 0x2fe7e37c dyld::loadPhase4(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 128
8 dyld 0x2fe7e29c dyld::loadPhase3(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 984
9 dyld 0x2fe7dc36 dyld::loadPhase1(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 110
10 dyld 0x2fe7ada4 dyld::loadPhase0(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 168
11 dyld 0x2fe7ab58 dyld::load(char const*, dyld::LoadContext const&) + 208
12 dyld 0x2fe7f8da dlopen + 802
13 libdyld.dylib 0x39dee946 dlopen + 46
14 CoreFoundation 0x31ab4910 _CFBundleDlfcnLoadBundle + 128
15 CoreFoundation 0x31ab478c _CFBundleLoadExecutableAndReturnError + 356
16 Foundation 0x323d2154 -[NSBundle loadAndReturnError:] + 844
17 Visitor Self Service 0x000e251a -[CoreBundleManager bundleForName:] (CoreBundleManager.m:70)
18 Visitor Self Service 0x000cd418 -[CoreProcessDefinition processBundle] (CoreProcessDefinition.m:226)
19 Visitor Self Service 0x000cf17e -[CoreProcessRuntime loadControllerForStep:] (CoreProcessRuntime.m:187)
20 Visitor Self Service 0x000ce9f4 -[CoreProcessRuntime performNextStepInProcessDefinition] (CoreProcessRuntime.m:112)
21 Visitor Self Service 0x000ba642 __62-[DynamicViewController prepareControllerForProcessDefinition]_block_invoke (DynamicViewController.m:107)
22 libdispatch.dylib 0x39ddb790 _dispatch_call_block_and_release + 8
23 libdispatch.dylib 0x39dde8be _dispatch_after_timer_callback + 10
24 libdispatch.dylib 0x39ddb5d8 _dispatch_client_callout + 20
25 libdispatch.dylib 0x39ddc48a _dispatch_source_invoke + 254
26 libdispatch.dylib 0x39ddee04 _dispatch_main_queue_callback_4CF + 164
27 CoreFoundation 0x31afb1ac __CFRunLoopRun + 1284
28 CoreFoundation 0x31a6e238 CFRunLoopRunSpecific + 352
29 CoreFoundation 0x31a6e0c4 CFRunLoopRunInMode + 100
30 GraphicsServices 0x35629336 GSEventRunModal + 70
31 UIKit 0x3398a2b4 UIApplicationMain + 1116
32 Visitor Self Service 0x000b66d8 main (main.m:16)
33 libdyld.dylib 0x39deeb1c start + 0
答案 0 :(得分:2)
最后我开始工作了。
设置合适的捆绑包有几个步骤。
在Bundle set的Project Build Settings中
您还需要一个Info.plist
注意强>
Apple Review Guidelines禁止执行外部代码,因此只能在内部应用中执行。
2.7 以任何方式或形式下载代码的应用将被拒绝
2.8 安装或启动其他可执行代码的应用将被拒绝