리소스 집합을 번들로 묶으려고 시도하고 NSBundle을 통해 코드에서 액세스합니다.내 번들이 info.plist를 무시하는 이유는 무엇입니까?
지금까지는 번들의 리소스를 액세스 할 수 있지만 번들의 Info.plist 파일에서 메타 데이터를 가져 오기 위해 NSBundle 인스턴스를 가져올 수 없습니다.
이상하게도 처음 시도가 성공하여 메타 데이터를 올바르게 가져 왔지만 그 이후로이 동작을 복제 할 수 없었고 번들은 항상 bundleIdentifier 나 infoDictionary의 다른 항목에 대해 null을 반환합니다.
NSString *pathToTestBundle = [[NSBundle mainBundle] pathForResource:@"test"
ofType:@"testBundle"];
NSLog(@"path to Test Bundle: %@", pathToTestBundle);
NSBundle *testBundle = [NSBundle bundleWithPath: pathToTestBundle];
NSLog(@"testBundle: %@", testBundle);
NSString *identifier = [testBundle bundleIdentifier];
NSLog(@"testBundle identifier: %@", identifier);
NSURL *testResourceURL = [testBundle URLForResource:@"vanGroup"
withExtension:@"png"];
NSLog(@"testBundle test resource: %@", testResourceURL);
NSImage *testImage = [[NSImage alloc] initByReferencingURL:testResourceURL];
[imageView setImage:testImage];
NSLog(@"%@", [testBundle infoDictionary]);
이 제공 :
내가 다음 테스트 케이스에 코드를 감소 테스트 번들 (라인 길이 편집) 내 Xcode 프로젝트에서
path to Test Bundle: /.../BundleTester.app/Contents/Resources/test.testBundle
testBundle: NSBundle </../BundleTester.app/Contents/Resources/test.testBundle>
(not yet loaded)
testBundle identifier: (null)
testBundle test resource: file://.../BundleTester.app/Contents/Resources/test.testBundle/Resources/vanGroup.png
BundleTester[45083:707] {
NSBundleInitialPath = "/Users/diggory/Library/Developer/Xcode/DerivedData/BundleTester-hcbsnhudsdfzlyggjbvlkdbrtxrw/Build/Products/Debug/BundleTester.app/Contents/Resources/test.testBundle";
NSBundleResolvedPath = "/Users/diggory/Library/Developer/Xcode/DerivedData/BundleTester-hcbsnhudsdfzlyggjbvlkdbrtxrw/Build/Products/Debug/BundleTester.app/Contents/Resources/test.testBundle";
}
A와 추가 폴더 참조이며 다음 구조를 갖습니다.
test.testBundle
Info.plist
Resources
vanGroup.png
이미지 자원이 올바르게로드되었지만 val plist의 값은 무시됩니다.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.monkeyfood.testbundle</string>
<key>badger</key>
<string>Bodger</string>
</dict>
</plist>
내가 뭔가를 놓치고 다음과 같이
PLIST는? 내가 도대체 뭘 잘못하고있는 겁니까?
많은 감사.
번들을 사용한 적이 없습니다. 그러나 모든 번들에 "Contents"폴더가 포함되어 있지 않습니까? 번들을 사용하는 이유는 무엇입니까? – lbrndnr
Brilliant - 컨텐츠 폴더를 잊어 버렸습니다. 이제는 작동합니다. 덕분에 대단히 감사합니다. – Diggory
공식 답변이므로 답변을 추가했습니다 :) – lbrndnr