What is the alternative of [NSBundle mainBundle] URLForResource:withExtension: in iOS 3 SDK
Asked Answered
P

2

5

I am developing an iOS app using iOS 4.2 SDK, but I want the app to run on older devices like my iPhone 2G with iOS 3.1.3. I don't know what is the alternative for this code:

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"CoreDataApp" withExtension:@"momd"];

It crashes on my device, because the URLForResource:withExtension: method is iOS 4+.

Please help. Thanks.

Paludal answered 24/2, 2011 at 15:4 Comment(0)
A
6

its -

NSURL *aFileURL = [NSURL fileURLWithPath: [[NSBundle mainBundle]  pathForResource:path ofType:@"aif"]];
Anglophobe answered 24/2, 2011 at 15:9 Comment(0)
D
7

You can obtain path to your resource using pathForResource:ofType: method and then convert that path to URL using for example +fileURLWithPath: method in NSURL - both apis are available starting SDK 2.0.

NSString *path = [[NSBundle mainBundle] pathForResource:@"CoreDataApp" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:path];
Disparagement answered 24/2, 2011 at 15:8 Comment(0)
A
6

its -

NSURL *aFileURL = [NSURL fileURLWithPath: [[NSBundle mainBundle]  pathForResource:path ofType:@"aif"]];
Anglophobe answered 24/2, 2011 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.