Skip to content

Netzyn Player API for iOS

The Netzyn Player API for iOS allows an iOS application to embed the NZ Player functionality. This is accomplished by

  • Adding NetzynPlayer.xcframework to your app
  • Creating and adding NetzynPlayerviewController to your UIViewController, and add its corresponding view to your view hierarchy

The Netzyn Player SDK for iOS requires XCode 15 or later and iOS 16.2 or later.

Class NetzynPlayerViewController

This is the main UIKit class for the SDK. (For the SwiftUI View, see below). Add this view controller to your view controller hierarchy, and add its corresponding view to the view hierarchy.

When the last strong reference to NetzynPlayerViewController and its corresponding view is removed, the class is deallocated and the SDK will disconnect automatically.

Initializers

init(configuration:)

Creates a new instance with the specified configuration. This initializer constructs the view controller with the supplied configuration, and it will connect automatically.

NetzynPlayerViewController(configuration: Configuration)

Parameters:
configuration Configuration to connect the NetzynPlayerViewController

Example:

import UIKit
import NetzynPlayer

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        var configuration = Configuration(url: URL(string: "example.com")!)
        //adjust configuration as needed 

        let playerViewController = NetzynPlayerViewController(configuration: configuration)
        addChild(playerViewController)
        view.addSubview(playerViewController.view)
        playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            playerViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            playerViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
            playerViewController.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
            playerViewController.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)
        ])
    }
}

Currently only one simultaneous instance of NetzynPlayerViewController is supported.

init(coder:)

Called when unarchiving the view controller from a storyboard or nib file. Do not call this initializer yourself, instead rely on it to be called automatically during the unarchive process. When the view controller is unarchived from a storyboard or nib file, it is not possible to provide a configuration at that time. Instead, you can provide a configuration later in the lifecycle with the setConfiguration(configuration:) method.

NetzynPlayerViewController(coder: NSCoder)

Currently only one simultaneous instance of NetzynPlayerViewController is supported.

Methods

setConfiguration(configuration:)

Provides a configuration 'late'. In the case that the NetzynPlayerViewController is constructed via init(coder:), for example, because it is unarchived from a storyboard file or a xib, no configuration is provided at initialization time. If so, this method can provide a configuration after the view controller is created. Once supplied with a configuration, connection can proceed automatically.

func setConfiguration(configuration: Configuration) async

Parameters:
configuration The configuration to set
Precondition:
No configuration has been provided to the NetzynPlayerViewController. That is, neither init(configuration:) nor setConfiguration(configuration:) have been previously called on this instance.

Properties

errors

Returns an ErrorSequence of errors. You can iterate over this sequence with for await error in errors.

var errors: ErrorSequence

presentErrors

Whether errors ought to be presented automatically to the user. If true, errors will be presented as alerts. true is the default value.

var presentErrors: Bool = true

Class NetzynPlayerView

This is the main SwiftUI class for the SDK. (For the UIKit ViewController, see above). Add this view type to your SwiftUI hierarchy.

!!! Note "When the NetzynPlayerView is removed from the view hierarchy, the SDK is deallocated and it will disconnect automatically.

init(configuration:)

Creates a new instance with the specified configuration. This initializer constructs the SwiftUI view with the supplied configuration, and it will connect automatically.

NetzynPlayerView(configuration: Configuration)

Parameters:
configuration Configuration to connect the NetzynPlayerView

Currently only one simultaneous instance of NetzynPlayerView is supported.

SwiftUI View Effects

presentingErrors

Whether errors ought to be presented automatically to the user. If true, errors will be presented as alerts. true is the default value.

func presentingErrors(_ value: Bool) -> NetzynPlayerView

withErrors

Returns an ErrorSequence of errors. You can iterate over this sequence with for await error in errors.

func withErrors(_ callback: @escaping (ErrorSequence) -> Void) -> NetzynPlayerView

Struct Configuration

A Configuration models the information needed to connect to the Netzyn Cloud.

Initializers

init(url:commandLineArgs:)

Creates the configuration with the specified parameters.

Configuration(url: URL, commandLineArgs: String = "")

Parameters:
url The URL to connect to. Please contact support@netzyn.com to get a provisioned cloud URL. To run a specific app, append the app name to the URL path. For example, example.com/specificappname.
commandLineArgs Additional low-level options to be passed to the SDK core. Supports many debugging and configuration options not directly exposed to the Swift API.

Properties

prefersMetalRenderer

When true, attempts to use the metal renderer. When false, uses the OpenGL renderer. The default value is true.

var prefersMetalRenderer: Bool = true

The Metal renderer is the modern high-performance default renderer for Apple platforms. To use the legacy OpenGL renderer instead, set this property to false.

!!! In the future, the legacy OpenGL renderer – and this API – will be removed. If you encounter bugs that require use of this property, please report them.

ErrorSequence

An opaque AsyncSequence of Swift.Error. To observe the errors produced by the SDK, use the for try await pattern.

Example:

//maintaining a weak reference ensures the viewcontroller does not remain allocated merely because of error handling
Task { [weak netzynPlayerViewController] in
    for try await error in netzynPlayerViewController?.errors {
        print("error")
    }
}
See also: NetzynPlayerViewController.presentsErrors.