Introducing the Modern WebKit API

Similar documents
Accessibility on ios. Developing for everyone. Frameworks #WWDC14. Session 210 Clare Kasemset ios Accessibility

ITP 342 Mobile App Dev. Web View

Accessibility on OS X

Creating Extensions for ios and OS X, Part Two

Seamless Linking to Your App

Using and Extending the Xcode Source Editor

What s New in Xcode App Signing

What s New in CloudKit

Monetize and Promote Your App with iad

Discovering WKWebView

Extending Your Apps with SiriKit

Mastering UIKit on tvos

Mastering Xcode for iphone OS Development Part 2. Marc Verstaen Sr. Manager, iphone Tools

Introducing Password AutoFill for Apps

Implementing UI Designs in Interface Builder

What s New in Core Location

Creating Extensions for Safari

What s New in tvos 12

Quick Interaction Techniques for watchos

What's New in Foundation Networking

Data Delivery with Drag and Drop

Introducing Swift Playgrounds

Content Protection for HTTP Live Streaming

Building Watch Apps #WWDC15. Featured. Session 108. Neil Desai watchos Engineer

WatchKit In-Depth, Part 2

JavaScript for Automation

Creating Content with iad JS

Creating Great App Previews

Media and Gaming Accessibility

Thread Sanitizer and Static Analysis

ios Accessibility Developing for everyone Session 201 Ian Fisch ios Accessibility

Improving the Accessibility and Usability of Complex Web Applications

Mastering Drag and Drop

Introducing the Photos Frameworks

Sam Weinig Safari and WebKit Engineer. Chris Marrin Safari and WebKit Engineer

Advanced Debugging and the Address Sanitizer

Designing for Apple Watch

Localizing with Xcode 6

Introducing On Demand Resources

What's New in UIKit Dynamics and Visual Effects Session 229

Advanced Scrollviews and Touch Handling Techniques

Automatic Strong Passwords and Security Code AutoFill

Storyboards and Controllers on OS X

Finding Bugs Using Xcode Runtime Tools

Using HTML5 Offline Storage. Brady Eidson Safari and WebKit Engineer

What s New in watchos

Getting the Most Out of HealthKit

Mastering Xcode for iphone OS Development Part 1. Todd Fernandez Sr. Manager, IDEs

Adapting to the New UI of OS X Yosemite

Advances in TVMLKit. App Frameworks #WWDC17. Trevor Cortez, Localization Engineer Parry Panesar, tvos Engineer Jeremy Foo, tvos Engineer

Creating Complications with ClockKit Session 209

Cross Platform Nearby Networking

Profiling in Depth. Do you know where your code is? Session 412. Kris Markel Performance Tools Engineer Chad Woolf Performance Tools Engineer

imessage Apps and Stickers, Part 2

Getting the Most out of Playgrounds in Xcode

Your Apps and Evolving Network Security Standards

WebGL. Creating Interactive Content with WebGL. Media #WWDC14. Session 509 Dean Jackson and Brady Eidson WebKit Engineers

Designing Great Apple Watch Experiences

Managing Documents In Your ios Apps

Leveraging Touch Input on ios

Introducing SiriKit. Hey Siri, say hello to apps #WWDC16. App Frameworks. Session 217

Introducing CloudKit. A how-to guide for icloud for your Apps. Frameworks #WWDC14. Session 208 Olivier Bonnet CloudKit Client Software

Modern User Interaction on ios

Enhancing your apps for the next dimension of touch

What s New in tvos #WWDC16. App Frameworks. Session 206. Hans Kim tvos Engineer

View Controller Advancements for ios8

New UIKit Support for International User Interfaces

Introduction to Siri Shortcuts

What s New in Notifications

Power, Performance, and Diagnostics

What s New in NSCollectionView Session 225

Vision Framework. Building on Core ML. Media #WWDC17. Brett Keating, Apple Manager Frank Doepke, He who wires things together

Improving your Existing Apps with Swift

What s New in Energy Debugging

Integrating Apps and Content with AR Quick Look

Advanced Memory Analysis with Instruments. Daniel Delwood Performance Tools Engineer

Address Book for iphone

What s New in Foundation for Swift Session 207

What s New in Testing

Your Apps and the Future of macos Security

DRS Access for Mobile Devices Final Report

Introducing the Contacts Framework

Mysteries of Auto Layout, Part 1

Page 1 of 20 webforms Browser Configuration Guide

View Controller Lifecycle

Adopting Advanced Features of the New UI

What s New in Core Data?

What's New in Core Spotlight

Developing Applications for ios

What s New in imessage Apps

App Extension Best Practices

Apple Watch Design Tips and Tricks

We need a browser that just works with modern web sites and services. I m worried about Internet security threats and the risk to my business

ArcGIS Enterprise Security: Advanced. Gregory Ponto & Jeff Smith

HKUST. CSIT 6910A Report. iband - Musical Instrument App on Mobile Devices. Student: QIAN Li. Supervisor: Prof. David Rossiter

Validating HTTP Live Streams

What s New in Cocoa for macos

Networking with NSURLSession

Using Advanced Interface Objects and Views

Building Apps with Dynamic Type

Transcription:

Frameworks #WWDC14 Introducing the Modern WebKit API Session 206 Anders Carlsson Safari and WebKit Engineer 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

WebKit Overview

WebKit in Your App

WebKit in Your App UIWebView UIKit.framework

WebKit in Your App UIWebView UIKit.framework WebView WebKit.framework

What You Will Learn

What You Will Learn Embedding web content in your app

What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API

What You Will Learn Embedding web content in your app Taking advantage of new features of the WebKit API Customizing how your app interacts with web content

The Modern WebKit API

The Modern WebKit API

The Modern WebKit API Same on ios and OS X

The Modern WebKit API Same on ios and OS X Modern

The Modern WebKit API Same on ios and OS X Modern Streamlined

The Modern WebKit API Same on ios and OS X Modern Streamlined Multi-process architecture

The Modern WebKit API Features

The Modern WebKit API Features Responsive scrolling

The Modern WebKit API Features Responsive scrolling Fast JavaScript

The Modern WebKit API Features Responsive scrolling Fast JavaScript Built-in gestures

The Modern WebKit API Features Responsive scrolling Fast JavaScript Built-in gestures Easy app-webpage communication

Multi-process Architecture

Multi-process Architecture Web content runs in its own process

Multi-process Architecture Web content runs in its own process WKWebView Web Content Process WebKit

Multi-process Architecture Consistently responsive

Multi-process Architecture Consistently responsive Energy efficient

Multi-process Architecture

Multi-process Architecture WKWebView

Multi-process Architecture WKWebView Web Content Process WebKit

Multi-process Architecture WKWebView WKWebView Web Content Process WebKit

Multi-process Architecture WKWebView WKWebView Web Content Process Web Content Process WebKit WebKit

Multi-process Architecture WKWebView WKWebView WKWebView Web Content Process Web Content Process WebKit WebKit

Multi-process Architecture WKWebView WKWebView WKWebView Web Content Process Web Content Process WebKit WebKit

Multi-process Architecture WKWebView WKWebView WKWebView Web Content Process Web Content Process WebKit WebKit

Multi-process Architecture WKWebView WKWebView Web Content Process WebKit

Multi-process Architecture WKWebView Web Content Process WebKit

Multi-process Architecture

Adopting the Modern WebKit API

Adopting the Modern WebKit API WKPedia a Wikipedia browsing app

Adopting the Modern WebKit API Creating a WKWebView

Adopting the Modern WebKit API Creating a WKWebView WKWebView *webview = [[WKWebView alloc] initwithframe:myframe];

Adopting the Modern WebKit API Loading a webpage

Adopting the Modern WebKit API Loading a webpage NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki"];

Adopting the Modern WebKit API Loading a webpage NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki"]; NSURLRequest *request = [NSURLRequest requestwithurl:url];

Adopting the Modern WebKit API Loading a webpage NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki"]; NSURLRequest *request = [NSURLRequest requestwithurl:url]; [webview loadrequest:request];

Adopting the Modern WebKit API Configurations Configuration WKWebView WKWebView WKWebView

Adopting the Modern WebKit API Configurations WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];

Adopting the Modern WebKit API Configurations WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; WKWebView *webview = [[WKWebView alloc] initwithframe:myframe configuration:configuration];

Adding App UI

Adding App UI

WKWebView Actions

WKWebView Actions - goback: - goforward: - reload: - stoploading:

WKWebView Actions - goback: - goforward: - reload: - stoploading:

Adding App UI

WKWebView Properties

WKWebView Properties Name Type title NSString URL NSURL loading BOOL estimatedprogress double

WKWebView Properties Name Type title NSString URL NSURL loading BOOL estimatedprogress double

WKWebView Properties Name Type title NSString URL NSURL loading BOOL estimatedprogress double

Customizing Page Loading

Page Loading

Page Loading Action

Page Loading Action Link

Page Loading Action

Page Loading Action window.location = 'http://www.apple.com/';

Page Loading Action

Page Loading Action -[WKWebView loadrequest:]

Page Loading Trigger Action Request

Page Loading Action Request Response

Page Loading Action Request Response

Page Loading Action Request Response

Page Loading Action Request Response Data

Page Loading 0 1 0 Action 1 0 1 1 0 0 1 0 1 0 Request Response Data

Page Loading Action Request Response Data

Page Loading Action Your App Request Response Your App Data

Customizing Page Loading @property (nonatomic, weak) WKNavigationDelegate *navigationdelegate;

Customizing Page Loading @property (nonatomic, weak) WKNavigationDelegate *navigationdelegate; - webview:decidepolicyfornavigationaction:decisionhandler:

Customizing Page Loading @property (nonatomic, weak) WKNavigationDelegate *navigationdelegate; - webview:decidepolicyfornavigationaction:decisionhandler: - webview:decidepolicyfornavigationresponse:decisionhandler:

Customizing Page Loading WKNavigationAction

Customizing Page Loading WKNavigationAction Name Type navigationtype WKNavigationType sourceframe WKFrameInfo destinationframe WKFrameInfo request NSURLRequest modifierflags NSEventModifierFlags

Customizing Page Loading WKNavigationAction Name navigationtype Type WKNavigationType Link sourceframe WKFrameInfo destinationframe WKFrameInfo request NSURLRequest modifierflags NSEventModifierFlags -[WKWebView loadrequest:]

Customizing Page Loading WKNavigationAction Name Type navigationtype WKNavigationType sourceframe WKFrameInfo destinationframe WKFrameInfo request NSURLRequest modifierflags NSEventModifierFlags

Customizing Page Loading WKNavigationAction Name Type navigationtype WKNavigationType sourceframe WKFrameInfo Shift destinationframe WKFrameInfo request NSURLRequest modifierflags NSEventModifierFlags Option Control

Customizing Page Loading WKNavigationResponse

Customizing Page Loading WKNavigationResponse Name Type response NSURLResponse formainframe BOOL canshowmimetype BOOL

Customizing Page Loading WKNavigationResponse Name Type response NSURLResponse formainframe BOOL canshowmimetype BOOL

Customizing Page Loading Decision Handler

Customizing Page Loading Decision Handler You decide whether to cancel or allow

Customizing Page Loading Decision Handler You decide whether to cancel or allow Navigation action WKNavigationActionPolicyCancel WKNavigationActionPolicyAllow

Customizing Page Loading Decision Handler You decide whether to cancel or allow Navigation action WKNavigationActionPolicyCancel WKNavigationActionPolicyAllow Navigation response WKNavigationResponsePolicyCancel WKNavigationResponsePolicyAllow

Customizing Page Loading Decision Handler You decide whether to cancel or allow Navigation action WKNavigationActionPolicyCancel WKNavigationActionPolicyAllow Navigation response WKNavigationResponsePolicyCancel WKNavigationResponsePolicyAllow Asynchronous

Demo WKPedia Beth Dakin Safari and WebKit Engineer

Gestures Navigation Gestures

Gestures Navigation Gestures webview.allowsbackforwardnavigationgestures = YES;

Gestures Zoom Gestures

Gestures Zoom Gestures OS X webview.allowsmagnification = YES;

Customizing Webpage Content

Customizing Webpage Content User Scripts

Customizing Webpage Content User Scripts Script Messages

Customizing Webpage Content User Scripts Script Messages Managed by WKUserContentController

WKUserContentController

WKUserContentController Part of WKWebViewConfiguration

WKUserContentController Part of WKWebViewConfiguration @property (nonatomic, strong) WKUserContentController *usercontentcontroller;

User Scripts

User Scripts

User Scripts

User Scripts When they run

User Scripts When they run Document start

User Scripts When they run Document start Document end

User Scripts When they run Document start Document end Where they run

User Scripts When they run Document start Document end Where they run All frames

User Scripts When they run Document start Document end Where they run All frames Main frame only

User Scripts

User Scripts NSString *myscriptsource = @"alert('hello, World!')";

User Scripts NSString *myscriptsource = @"alert('hello, World!')"; WKUserScript *myuserscript = [[WKUserScript alloc] initwithsource:myscriptsource injectiontime:wkuserscriptinjectiontimeatdocumentstart formainframeonly:yes];

User Scripts NSString *myscriptsource = @"alert('hello, World!')"; WKUserScript *myuserscript = [[WKUserScript alloc] initwithsource:myscriptsource injectiontime:wkuserscriptinjectiontimeatdocumentstart formainframeonly:yes]; [usercontentcontroller adduserscript:myuserscript];

What Can User Scripts Do?

What Can User Scripts Do? Incredibly powerful

What Can User Scripts Do? Incredibly powerful Modify the document

What Can User Scripts Do? Incredibly powerful Modify the document Listen for events

What Can User Scripts Do? Incredibly powerful Modify the document Listen for events Load resources

What Can User Scripts Do? Incredibly powerful Modify the document Listen for events Load resources Communicate back to your application

Script Messages

Script Messages

Script Messages

Script Messages Sent as JSON

Script Messages Sent as JSON Converted to Objective-C types

Script Messages Registering a Script Message Handler

Script Messages Registering a Script Message Handler WKScriptMessageHandler protocol

Script Messages Registering a Script Message Handler WKScriptMessageHandler protocol - (void)usercontentcontroller:(wkusercontentcontroller *)usercontentcontroller didreceivescriptmessage:(wkscriptmessage *)message;

Script Messages Registering a Script Message Handler WKScriptMessageHandler protocol - (void)usercontentcontroller:(wkusercontentcontroller *)usercontentcontroller didreceivescriptmessage:(wkscriptmessage *)message; [usercontentcontroller addscriptmessagehandler:handler name:@"myname"];

Script Messages Posting messages

Script Messages Posting messages window.webkit.messagehandlers.<name>.postmessage();

Script Messages Posting messages window.webkit.messagehandlers.<name>.postmessage(); function postmymessage() { var message = { 'message' : 'Hello, World!', 'numbers' : [ 1, 2, 3 ] }; window.webkit.messagehandlers.myname.postmessage(message); }

Script Messages Receiving messages

Script Messages Receiving messages - (void)usercontentcontroller:(wkusercontentcontroller *)usercontentcontroller didreceivescriptmessage:(wkscriptmessage *)message { NSLog(@"Message: %@", message.body); }

Script Messages WKScriptMessage Name Type body id webview WKWebView name NSString

Script Messages

Script Messages The webpage can call postmessage

Script Messages The webpage can call postmessage Great for allowing webpages to interact with your app

Script Messages The webpage can call postmessage Great for allowing webpages to interact with your app Handle invalid messages

Demo WKPedia for ipad Beth Dakin Safari and WebKit Engineer

The Modern WebKit API

The Modern WebKit API

The Modern WebKit API WKWebView Web Content Process WebKit

The Modern WebKit API

The Modern WebKit API

The Modern WebKit API

WKScriptMessageHandler WKWebView WKNavigationDelegate WKBackForwardListItem WKFrameInfo WKUserContentController WKBackForwardList WKNavigation WKScriptMessage WKPreferences WKNavigationType WKUIDelegate WKUserScript WKProcessPool WKNavigationAction WKNavigationResponse WKWebViewConfiguration WKWindowFeatures

Next Steps

Next Steps Adopt the modern WebKit API

Next Steps Adopt the modern WebKit API Give us feedback

More Information Evangelism evangelism-frameworks@apple.com Safari Dev Center http://developer.apple.com/safari/ WebKit Open Source Project http://www.webkit.org/ Apple Developer Forums http://devforums.apple.com/

Related Sessions Your App, Your Website, and Safari Nob Hill Tuesday 4:30PM Web Inspector and Modern JavaScript Russian Hill Thursday 10:15AM Sharing Code Between ios and OS X Presidio Friday 9:00AM

Labs Safari and WebKit Lab Media Lab B Tuesday 4:30PM Safari and WebKit Lab Media Lab B Wednesday 4:30PM Safari and WebKit Lab Media Lab B Thursday 2:00PM