开发者

XCode - (iOS) Calling a local HTML file in to a SplitView via .plist reference?

Newbie here (as may be evident by the question) but after many many hours of trying to figure this one out I have hit a point I need to ask for help...

Basically, all I want to do is parse a string from an array populated within a .plist. This string being a local URL. It works perfectly for external URL's, but no matter what I have tried for a local URL, all I get is nothing - Not even a URL not found (I lie - that did happen once but to never again 开发者_JAVA技巧be replicated).

Any and all help will be greatly appreciated!

I have this code in DetailViewController:

    NSString *attractionURL = [detailItem description];
    NSURL *url = [NSURL URLWithString:attractionURL];
    [wikiView loadRequest:[NSURLRequest requestWithURL:url]];

And this code in a popOver (RootViewController):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"recipes"
                        ofType:@"plist"];
    attractions = [[NSArray alloc] initWithContentsOfFile:path];

    self.title = @"Recipes";

With the URL's in a .plist file:

<array>
    <array>
        <string>Sirloin</string>
        <string>http://Resources/iPad/index.html</string>
    </array>
    <array>
        <string>Chasseur</string>
        <string>http://www.jamesmartinsfood.com</string>
    </array>

</array>
</plist>

Like I say, external URL works fine, local just doesn't do squat...

Cheers!


Your local URL isn't defined properly, it shouldn't have http:// as it is not hosted on an http server.

It should be in a format like the following.

file://localhost/var/mobile/Application/${APP_ID}/MyApp.app/index.html

The first part is potentially ever changing based on device/environment and you will need to rely on the OS Framework to determine it, so in your plist you would only define the relative path to the local files and then prepend the path provided by the OS.

Something along the lines of

NSString *path = [[NSBundle mainBundle] pathForResource:myFileName ofType:myFileExtension];

Might work for you, where you myFileName is "index" and myFileExtension is "html"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜