Using Safari to debug a WebView

Source: Internet
Author: User


In the process of web development, it is very common to grab the package, debug the page style, and view the request header. In fact, in iOS development, these skills can also be used (whether the simulator or the real machine), but we need to use the Mac's own browser Safari. So, this article explains how to use Safari to debug WebView in an iOS program.

Environmental information:

Mac OS X 10.10.1

Xcode 6.1.1

IOS 8.1

Body:

1. Open the developer mode of the simulator (real machine)

"Settings", "Safari", "Advanced", "Web Inspector" open

Open the Web inspector in your iphone device

2. Open the Safari developer mode on your Mac

"Safari", "preferences", "Advanced", "show the development menu in the menu bar" tick

Open the developer mode in Safari

3. Write a webview and load a Web page
#import"ViewController.h" @interfaceViewController () @property (strong, nonatomic) Span class= "hljs-built_in" >uiwebview *webview;  @end  @implementation viewcontroller-(void) viewdidload {[superviewdidload]; //do any additional setup after loading the view, typically from a nib. _webview = [[uiwebviewalloc] initwithframe: Self.view.bounds]; [_webview loadrequest:[nsurlrequest requestwithurl:[ Nsurl urlwithstring:@ "http://www.baidu.com"]]; [self.view Addsubview:_webview];}  @end             
4. Open the WebView app in the simulator (real machine) and open Safari to view network information

"Developing", "IOS Simulator", "Web site being debugged"

Note: You must webview when you load the Web page to open Safari to see Debug mode.

Turn on debugging in Safari

In the Debug window that pops up, you can see the various information that is currently loading the Web page, including the source code, the request header, the picture, the loaded resources and scripts, the console output, and so on. And it is the same as the Web front-end debugging, you can directly modify the CSS style of the Web page, the layout of the page and other changes, without re-running the entire app.

5. Modifying Web Styles

With the cursor selected for the style you want to modify, you can see the modified effect directly in the emulator.

Modify the styles in WebView directly

Of course, there are many debugging techniques for WebView, such as Charles Tools.

Using Safari to debug a WebView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.