HTML5接入與OC互動

餘二五發表於2017-11-22

////螢幕

#define SHENGHUO_WIDTH    ([UIScreen mainScreen].bounds.size.width)

#define SHENGHUO_HEIGHT   ([UIScreen mainScreen].bounds.size.height)


#import “SHFindVC.h”

//

////HTML5接入測試

//#import “WebViewJavascriptBridge.h”

//#import “Html5ReportWebView.h”


@interface SHFindVC ()


@end




@implementation SHFindVC


– (void)viewDidLoad {

    [super viewDidLoad];


    _commodityHtml.delegate=self;

    NSUserDefaults *userInfo = [NSUserDefaults standardUserDefaults];

    NSMutableArray *userid = [userInfo objectForKey:@”userId”];

    //正式服

    NSString *newUrl = [NSString stringWithFormat:@”%@”,userid];

    NSLog(@”%@”,newUrl);

    NSURL *htmlUrl = [NSURL URLWithString:@”http://”];

    

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@”%@%@”,htmlUrl,newUrl]];

    

    NSLog(@”%@”,url );


    [_commodityHtml loadRequest:[NSURLRequest requestWithURL:url]];

    


    

    


}



– (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    

   

    NSString *absoluteString = request.URL.absoluteString;

    NSLog(@”TAP == %@”,absoluteString);

    if ([absoluteString rangeOfString:@”login”].location != NSNotFound) {

        

        UIAlertView * alertView = [[UIAlertView allocinitWithTitle:@”提示 message:@”申請請求登入!! delegate:nil cancelButtonTitle:@”確定 otherButtonTitlesnil];

        [alertView show];

        

    }

    

    

return YES;

    

}


– (IBAction)addContent:(id)sender {

    NSString * js = @” var p = document.createElement(`p`); p.innerText = `new Line`;document.body.appendChild(p);”;

    [_commodityHtml stringByEvaluatingJavaScriptFromString:js];

}





//隱藏頂部導航欄

– (void)viewWillAppear:(BOOL)animated {

      [self setFullScreen:YES];

  }


 – (void)viewWillDisappear:(BOOL)animated {

      [self setFullScreen:NO];

 }


 – (void)setFullScreen:(BOOL)fullScreen {

     // 狀態條

     [UIApplication sharedApplication].statusBarHidden = fullScreen;

   // 導航條

     [self.navigationController setNavigationBarHidden:fullScreen];

   // tabBar的隱藏通過在初始化方法中設定hidesBottomBarWhenPushed屬性來實現。

 }




@end


本文轉自 卓行天下  51CTO部落格,原文連結:http://blog.51cto.com/9951038/1957964,如需轉載請自行聯絡原作者


相關文章