This document provides an in-depth walkthrough of the features available to you after adding and initializing a ForemWebView instance in your project.
It's important to know this is a custom implementation of WKWebView and you should not implement your own WKNavigationDelegate logic. Please rely on the provided ForemWebViewDelegate for callbacks.
- Load a Forem instance URL
- After the first load of a valid Forem instance the variable
foremInstancewill be populated with corresponding metadata - As soon as the
foremInstancemetadata is populated any attempts to navigate (programmatically or by the user) outside the Forem instance will be restricted by theForemWebViewitself - A simple way to get started would be to call
.load("https://dev.to")on yourForemWebViewinstance
- After the first load of a valid Forem instance the variable
- Implement
ForemWebViewDelegatefor callbacks - Observe changes in the view's variables:
userDatawill be updated when a user logs in/out (ForemUserDataornilif unauthenticated)estimatedProgress,canGoBack,canGoForward,url, and any other WKWebView variable for state updates
load(_ urlString: String)- Helper method for simplicity:
webView.load("https://dev.to")
- Helper method for simplicity:
userData- Instance of
ForemUserDatawhen authenticated ornilotherwise
- Instance of
foremInstanceForemInstanceMetadatastruct that represents the Forem Instance loaded. It will beniluntil the first page load
fetchUserData(completion: @escaping (ForemUserData?) -> Void)- Async callback to request the
ForemUserDatastruct from the current state of the DOM - Instead of polling with this function we recommend you register to observe the
userDatavariable as you'll react to changes when they become available
- Async callback to request the
fetchUserData(completion: @escaping (ForemUserData?) -> Void)
Extension to URL
.isOAuthUrl -> Bool- Responds to whether the url is one of the supported 3rd party redirect URLs in a OAuth protocol
- Useful if implementing
WKNavigationDelegateon your own (not recommended)
In order for your App to take advantage of these native features via the ForemWebView you'll need to configure a few things:
- Make sure you enable
Audio, AirPlay, and Pciture in Picturefrom the Background Mode capability in your Project's Target - Configure the AVAudioSession category to
.playback, preferrably in your AppDelegate.- A one liner that works for this is
try? AVAudioSession.sharedInstance().setCategory(.playback)although handling the error will most likely prove helpful.
- A one liner that works for this is
- The
ForemWebViewwill call.setActive(true)on theAVAudioSessionshared instance when playback is initiated, so you don't need to make this call yourself. - The
ForemWebViewDelegatemethodwillStartNativeVideowill be called when the native video player is ready to start playing. It's your responsibility to present thisAVPlayerViewController
The podcast player will automatically take advantage of Background audio playback. If background playback is unavailable/unsupported the Podcast Player will still play the audio in your App in the foreground. However, when the App is sent to the background you'll be missing better Artwork, controls, and the playback will stop after some time.