UIWebView - 1

来源:互联网 发布:windows 系统更新慢 编辑:程序博客网 时间:2024/06/04 23:19

UIWebview的使用和学习都不难,直接贴上来的一个例子,并且带有菊花的

#import "ViewController.h"#import "OpenUDID.h"            //获取用户的OpenUDID#import "macaddress.h"          //获取用户的macaddress#import <AdSupport/AdSupport.h>#define WAP_URL @"requested web address "@interface ViewController ()<UIWebViewDelegate>@property (nonatomic, strong) UIWebView* webView;@property (nonatomic, strong) NSString* mainUrl;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];        // 添加加载画面    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 48.0f, 48.0f)];    [_activityIndicator setCenter:self.view.center];    [_activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];    [_activityIndicator setHidesWhenStopped:YES];    [_activityIndicator startAnimating];        // 添加WebView并加载WAP_URL    NSString * platform = @"ios";    NSString * bundleid = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];    NSString * version  = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];    NSString * openudid = [OpenUDID value];    NSString * idfv     = [[[UIDevice currentDevice] identifierForVendor] UUIDString];    NSString * macaddr  = [MacAddress GetMacAddress];    NSString * idfa     = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];    self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];        self.mainUrl =[NSString stringWithFormat:WAP_URL,                   platform,                   bundleid,                   macaddr,                   idfa,                   idfv,                   openudid,                   version];        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.mainUrl]                                          cachePolicy:NSURLRequestReturnCacheDataElseLoad                                      timeoutInterval:120.00]];    [self.webView setDelegate:self];    self.webView.hidden = YES;    [self.view addSubview:_activityIndicator];    [self.view addSubview:self.webView];}// 更新app应用- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{    NSString *urlStr = [[request  URL] absoluteString];        //结合 itms协议,如果点击了协议之后页面立即返回主页,不然默认空白    if ([urlStr hasPrefix:@"itms-services"]) {        [[UIApplication sharedApplication] openURL:[request URL]];                        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.mainUrl]                                                   cachePolicy:NSURLRequestReturnCacheDataElseLoad                                               timeoutInterval:120.0]];        [self.view addSubview:self.webView];                return NO;    }        return YES;}# pragma mark - Web View Delegate// 数据加载完- (void)webViewDidFinishLoad:(UIWebView *)webView {    [_activityIndicator stopAnimating];    webView.hidden = NO;}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    }@end


其实UIWebView还有很多缓存啊等等的很多的接口方法,都有待我们去学习和使用。

0 0
原创粉丝点击