iOSwebView解析pdf的简单使用

本文介绍如何在iOS应用中使用UIWebView展示网页内容。通过创建一个简单的应用实例,演示了如何设置UIWebView并加载指定网址。此外,还分享了解决代理服务器导致加载失败的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

移动互联网应用开发中的一个必备功能是将浏览器作为视图嵌入到应用中去。在iOS中是UIWebView。

文本写了一个最简单的WebView应用,截图:

image

WebView展示的是我博客首页。

可参照编写简单的视图切换应用创建一个简单的windows based application。不同在于拖拽View到视图以后,在上面再拖拽的是Navigation Bar和WebView。类似下面:

 imageimage

拖拽后的效果:

image

在Controller的头文件中要设置Outlet:

@interface WebKitController : UIViewController { 
    UIWebView *webView; 
    UINavigationBar *navigationBar; 
}

@property (nonatomic,retain) IBOutlet UIWebView *webView; 
@property(nonatomic,retain) IBOutlet UINavigationBar *navigationBar;

 

在Controller的实现文件中:

@synthesize webView; 
@synthesize navigationBar;

 

- (void)viewDidLoad { 
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"<a href="http://marshal.easymorse.com"]]];”>http://marshal.easymorse.com"]]];</a> <br />    navigationBar.topItem.title=@"我的主页"; <br />    [super viewDidLoad]; <br />}</p><p> </p></blockquote><p>然后,就是在IB上将WebView和NavigationBar做关联,结果类似这样:</p><p><a href=" http:="" marshal.easymorse.com="" wp-content="" uploads="" 2010="" 10="" image32.png"="" style="color: rgb(16, 26, 82); font-weight: 800; text-decoration: none; ">image

这里要注意的是,如果mac系统设置了代理服务器,这时最好关掉。我就碰到了启动应用后白屏,因为我们的代理服务器有认证,在这里调用的WebView不会弹出输入用户名密码。

本demo是WKWebView的基本使用和交互 ,实现了原生调用js的方法、js调用原生的方法、通过拦截进行交互的方法;修改内容 加入沙盒 / /加载沙盒 不带参数 // NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString * path = [paths objectAtIndex:0]; // path = [path stringByAppendingString:[NSString stringWithFormat:@"/app/html/index.html"]]; // NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"file://%@",path] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]] relativeToURL:[NSURL fileURLWithPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject]]; // [self.wkView loadFileURL:url allowingReadAccessToURL:[NSURL fileURLWithPath: [paths objectAtIndex:0]]]; // 带参数 /* NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString * path = [paths objectAtIndex:0]; path = [path stringByAppendingString:[NSString stringWithFormat:@"/app/html/index.html"]]; NSURL * url = [NSURL fileURLWithPath:path isDirectory:NO]; NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; [queryItemArray addObject:[NSURLQueryItem queryItemWithName:@"version" value:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]]]; [urlComponents setQueryItems:queryItemArray]; [self.wkView loadFileURL:urlComponents.URL allowingReadAccessToURL:[NSURL fileURLWithPath: [paths objectAtIndex:0]]]; */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值