1、with respect to any of the technology describedin this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers.1 Infinite Lo
2、opCupertino, CA 95014408-996-1010Apple, the Apple logo, Carbon, Cocoa, Mac, Mac OS, Objective-C, Pages, QuickTime, Safari, and Xcode are trademarks of Apple Inc., registered in the United States and other countries.WebScript is a trademark of Apple Inc.Java is a registered trademark of Oracle and/or
3、 its affiliates.Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE
4、 READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages.THE WARRANTY AND REME
5、DIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty.Some states do not allow the exclusion or limitation of implied warranties or liabili
6、ty for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.ContentsIntroduction to WebKit Objective-C Programming Guide 9What Is the WebKit? 9W
7、ho Should Read This Document?Organization of This Document 10See Also 11Why Use the WebKit? 13Core WebKit Classes 15Frame Model and View Classes 15Data Model and View Classes 16Provisional vs. Committed Data Sources 17WebView Delegates 18Simple Browsing 21Multiple Windows 23Opening Windows 23Enterin
8、g URLs 23Handling New Window Requests 24Loading Pages 27Sequence of Frame Load Delegate Messages 27Testing for the Main Frame 28Displaying the Current URL 28Displaying the Page Title 28Displaying Load Status 29Loading Resources 31Sequence of Resource Load Delegate Messages 31Identifying Resources 31
9、Tracking Resource Load Progress 32Paging Back and Forward 35Enabling and Disabling the Back-Forward List 35Adding Back and Forward Buttons 3532009-07-28 | 2003, 2009 Apple Inc. All Rights Reserved.Setting the Page Cache 35Setting the Capacity 36The Current Item 36Managing State 36Managing History 37
10、Sharing History Objects 37Adding and Removing History Items 37Loading a History Item 38Saving and Loading History Objects 38Making Policy Decisions 39Enabling Editing 41Saving and Loading Web Content 43Modifying the Current Selection 45Changing Editing Behavior 47Should Methods 47Did Methods 47Using
11、 Undo When Editing 49Using the Document Object Model from Objective-C 51Interpreting the DOM Specification 51Handling Exceptions 53Using the Document Object Model Extensions 55Using JavaScript From Objective-C 57Spoofing 59Accessing the WebKit From Carbon Applications 61Determining WebKit Availabili
12、ty 63Testing for URL Loading System Availability 634Testing for WebKit Availability 63Isolating Your WebKit and URL Loading System Symbols 64Conditionally Loading Code 64Weak Linking Symbols 64Document Revision History 6756Figures and ListingsFigure 1 WebView and WebFrameView objects 16Figure 2 WebF
13、rame and WebDataSource objects 17Figure 3 Typical website 18Listing 1 Determining if the URL Loading system is available. 63Listing 2 Determining if the WebKit framework is available 63Listing 3 Loading WebKit constants dynamically using CFBundle 6578Introduction to WebKit Objective-C Programming Gu
14、ideConcurrency Note: The WebKit framework is not thread safe. If you call functions or methods in this framework, you must do so exclusively on the main program thread.The WebKit provides a set of core classes to display web content in windows, and by default, implements features such as following l
15、inks clicked by the user. The WebKit greatly simplifies the complicated processof loading webpagesthat is, asynchronously requesting web content from an HTTP server over the network where the response may arrive incrementally, in random order, or partially due to network errors. The WebKit also simp
16、lifies the process of displaying content that can contain various MIME types, and multiple frames each with their own set of scrollbars.You use the WebKit to display web content in a window of your application. Its as simple as creating a view, placing it in a window, and sending a URL load request
17、message. By default, your WebKit application behaves as you would expect without error. The WebKit conveniently creates and manages all the views needed to handle different MIME types. When the user clicks on a link in a page, the WebKit automatically creates the views needed to display the next pag
18、e.However, the WebKit doesnt implement a complete set of web browser features. You can, however, extend the WebKit by implementing custom delegate, view, and model objects. For example, you can implement a delegate to display load status, and the current URL.The WebKit also offers web content editin
19、g. If you enable editing in your WebView, users can edit the web content it displays. You can programmatically control the current selection and control editing behavior using a WebView delegate. You can also modify the Document Object Model directly using an Objective-C API.You can also access Java
20、Script from Objective-C and vice versa.The WebKit Objective-C API is specifically designed for embedding web content in your Cocoa or Carbon applicationsdeveloping web client applications not web server applications or web content. It is also not suitable for implementing non-GUI applications such a
21、s web crawlers. If you are a web content creator or JavaScript programmer, refer to WebKit DOM Programming Topics. 9Important: Currently, this API is available in Objective-C only. A minimal C API is provided for embedding web browser views in Carbon applications. You can use Objective-C in combinat
22、ion with C. The WebKit works with all versions of Mac OS X 10.2 that have Safari 1.0 installed.Organization of This DocumentThe following articles cover key concepts in understanding how the WebKit works: “Why Use the WebKit?” (page 13) describes the purpose of the WebKit and why you might want to u
23、se it in your applications. “Core WebKit Classes” (page 15) describes the core WebKit classes and the object-oriented design that is fundamental to understanding how the WebKit works.The following articles explain how to display web content in views: “Simple Browsing” (page 21) shows how to embed we
24、b content in your application by following a few simple steps. “Multiple Windows” (page 23) shows how to add support for multiple windows, and open windows automatically. “Loading Pages” (page 27) shows how to track the progress of loading frame content. “Loading Resources” (page 31) shows how to tr
25、ack the progress of loading individual resources on a page. “Paging Back and Forward” (page 35) shows how to implement a back-forward list and add Back andForward buttons to your application. “Managing History” (page 37) shows how to maintain a history of all the visited pages, and allow the user to
26、 go to a previously visited page. “Spoofing” (page 59) shows how to use user-agent strings. “Accessing the WebKit From Carbon Applications” (page 61) explains how to embed web content inCarbon applications. “Determining WebKit Availability” (page 63) explains how to determine if the WebKit is availa
27、ble on your system.The following articles explain how to implement web content editing: “Enabling Editing” (page 41) shows how to enable user editing in a WebView. “Saving and Loading Web Content” (page 43) shows how to save and load web content edited by the user. “Modifying the Current Selection” (page 45) shows how to programmatically modify th
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1