Start publishing with Swift on iOS®
Create a client that publishes data through topics on Diffusion™ Cloud. This example uses Swift to create a publishing client.
To complete this example, you need Apple's Xcode installed on your development system and a Diffusion Cloud service. For more information about getting a Diffusion Cloud service, see Getting started with Diffusion Cloud.
You also require a named user that has a role with the "TOPIC_CONTROL" role. For more information about roles and permissions, see Role-based authorization.
and permissions. For example, theThis simple publishing example connects to Diffusion Cloud using a principal and password credentials. It then adds a string topic. Once it has received a response from Diffusion Cloud to say that the topic has been created it then updates it to a value of "Hello World" using the non-exclusive string value updater, obtained from the topic update control feature.
You will need a caller to instantiate a new SimplePublisher instance and then call publish().
Full example
import Foundation import Diffusion class SimplePublisher { func publish() { // Connect to Diffusion Cloud let credentials = PTDiffusionCredentials(password: "<password>") let configuration = PTDiffusionSessionConfiguration( principal: "<system user>", credentials: credentials) let url = NSURL(string: "wss://host_name") PTDiffusionSession.open(with: url! as URL, configuration: configuration) { (session, error) -> Void in // Add the topic session!.topicControl.add(withTopicPath: "example/topic", type: PTDiffusionTopicType.string) { (error) -> Void in // Update the topic let updater = session!.topicUpdateControl.updater.stringValueUpdater() updater.update(withTopicPath: "example/topic", value: "Hello World") { (error) -> Void in } } } } }
This page last modified: 2017/07/03