简体   繁体   中英

Display a local web page in a UIWebView

I am trying to display a local web page in a UIWebView . The local web page is a PHP file and stored in the Supporting Files folder then a folder I created called webpages. I tried this code but it doesn't work.

@synthesize web;

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"php" inDirectory:@"web"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [web loadRequest:request];
    [web setDelegate:self];
    [web loadRequest:request];
}

您无法在UIWebView加载PHP文件,因为PHP需要服务器才能运行。

You can't run a local php file through UIWebView. PHP is a server side scripting language. OS X (and Windows) don't know how to interpret php code.

It seems to be an iPhone app your making, and running local php in your iPhone app is a no-go, and will continue to be for the foreseeable future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM