WebView Implementation ios
IOS SDK
Add Primis Player to a WebView presenting HTML content
Adding an HTML Div element to the page
In this type of integration, the Primis player is overlaid on top of the web content. For this to succeed the HTML page has to contain a Div element which will mark the position and width of the player. Its height will be updated later by PrimisPlayer.
- Add an HTML Div element to your web page with id=”primisPlayerSdkPlaceholder”
<div id="primisPlayerSdkPlaceholder"></div>
Note:
It is required that the Div element will have opening and closing tags.
Do not use <div id="primisPlayerSdkPlaceholder”/>
Initializing and configuring the player
- Add at the top of your ViewController class:
import PrimisPlayerSdk
#import <PrimisPlayerSdk/PrimisPlayerSdk-Swift.h>
For previous sdk versions, older than 2.0.0
import PrimisPlayer instead of PrimisPlayerSdk
- Define an instance variable for the Primis player:
var player: PrimisPlayer?
PrimisPlayer *player;
- Implement the WKNavigationDelegate protocol method didFinishNavigation and Initialize the player inside it. The player will require a placementID string and your webView.
- Note: YOUR_WEBVIEW is the WKWebView you are using on your app page
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
...
if player == nil {
player = PrimisPlayer()
player?.configure( [ .placementId: YOUR_PLACEMENT_ID_STRING,
.containerView: YOUR_WEBVIEW ] )
player?.add(to: self)
}
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
{
...
if (!player) {
player = [[PrimisPlayer alloc] init];
[player configure:@{
@(PrimisConfigKeyPlacementId): YOUR_PLACEMENT_ID_STRING,
@(PrimisConfigKeyContainerView): YOUR_WEBVIEW
}];
[player addTo: self];
}
}
- When a view controller that holds the Primis player is dismissed, release the player by using the ‘remove’ method. This is usually done inside deinit (swift) / dealloc (Obj-c).
player?.remove()
[player remove];
Updated 11 months ago