iOS API is provided in Swift language. It can be implemented on mobile applications running on iPhone, iPod and iPad. iOS APIs are provided as a dynamic library framework which implies that the applications using the framework can be submitted in the App Store only if their deployment target is iOS 8.0 or higher.
CocoaPods is a dependency manger tool which integrates frameworks to application. Sender iOS API library is available as smart-view-sdk pod at CocoaPods public repository.
Install and setup CocoaPods. Follow the steps there in CocoaPods Get Started
Add pod to Xcode project
Open ‘Podfile’ and add smart-view-sdk for pod name
pod ‘smart-view-sdk’
This gets latest version of SDK for Xcode available for download
To find more information about how to use pod for project, check Using CocoaPods.
Recommendation for iOS Framework
iOS SDK Library includes 2 types of framework.
iphoneos : only works on devices.(ARM)
iphoneos+iphonesimulator : works on devices and simulator( + i386,x86_64)
Apple appstore reject your app when register your app with iphoneos+iphonesimulator framework.
so, you should change iphoneos framework finally when you develop iphoneos+iphonesimulator framework, or you should remove manually that unused architectures from the final binary.
Importantyou need to run shell remove_unused_archs.sh to remove unused architectures from from the final binary. This script is in the iphoneos+iphonesimulator folder
Guidance to iOS developers before submitting Smart View enabled app
If you are using 'TestFlight Beta Testing' to distribute a prerelease build of your app, which requires several days to be tested, we ask you to invite a minimum of two testers from the table below.
One default and one regional so that we can simulate your chosen casting scenarios.
Also, please make sure that the Beta App Review process is finished before submitting the iOS test app on Seller site.
Region
Apple ID
All
apptest.sec@gmail.com
US
sqa.samex@gmail.com
EU
wacsprc@gmail.com wacsprc12@gmail.com
China
mercury5799@gmail.com
Rest of world
nishant.s1@samsung.com
API Usage
There are many features of the SDK and it's APIs. However, there are 3 main features that all Smart View apps need to implement.
Discover
Discover a compatible Samsung SmartTV on your network from your mobile application.
Launch
aunch applications on the TV from your mobile application.
Communicate
Connect and communicate with a TV application from your mobile app.
Discover TVs from a Mobile Application
From you mobile app, the first thing you'll want to do is find compatible TVs to interact with. Your mobile device and TV device need to be on the same WIFI network to work together. The mobile APIs provide a simple way to find TVs on your network. Typcially, you will use the APIs to start "scanning" the network for TVs and display a list to the user as they are found. Then allow the user to select a device to connect to.
The general mobile workflow is:
Start the Discovery Process
Listen for Events indicating services Added/Removed.
Present the list of discovered TVs to the user
Stop the Discovery Process
Once the user has selected a TV from the list
Example iOS API Usage
let serviceSearch = Service.search()
init () {
// The delegate is implemented as a weak reference
serviceSearch.delegate = self
serviceSearch.start()
}
// MARK: - ServiceSearchDelegate -
func onServiceFound(service: Service) {
// Update your UI by using the serviceDiscovery.services array
}
func onServiceLost(service: Service) {
// Update your UI by using the serviceDiscovery.services array
}
func onStop() {
// The ServiceSearch will call this delegate method after stopping the search
}
func onStart() {
// The ServiceSearch will call this delegate method after the search has started
}
// After the user connects to a device stop the search by calling
serviceSearch.stop( )
Alternatively, you can subscribe for notifications (Please unsubscribe when you are done).
var didFindServiceObserver: AnyObject? = nil
var didRemoveServiceObserver: AnyObject? = nil
func listenForNotifications()
{
didFindServiceObserver = NSNotificationCenter.defaultCenter().addObserverForName(MSDidFindService, object: serviceSearch, queue: NSOperationQueue.mainQueue( )) { (notification) -> Void in
let serviceSearch = notification.object as? ServiceSearch
let service = notification.userInfo["service"] as? Service
}
didRemoveServiceObserver = NSNotificationCenter.defaultCenter().addObserverForName(MSDidRemoveService, object: serviceSearch, queue: NSOperationQueue.mainQueue( )) { (notification) -> Void in
let serviceSearch = notification.object as? ServiceSearch
let service = notification.userInfo["service"] as? Service
}
}
If you want to use notifications, closures and the main queue for your notification you can use the equivalent convenience method call.
public func on(notificationName: String, performClosure: (NSNotification!) -> void) -> AnyObject
public func off(observer: AnyObject)
On selecting a service from the list of available services, you can interact with the service to get additional information about the device or you can either start, stop, install, and retrieve information about applications.
Installed applications can be launched.
Launching TV App from a Mobile Application
Before you can work with an TV app, you must first know the “id” of the TV application you want to work with. You can get your tv app id when you register your app in Samsung Apps.
Once the TV app has been released into Samsung Apps, you must use the supplied app id.
There are 4 core functions for working with installed tv apps
: Install the tv application (Only installed app is supported. Web Application is not supported.)
// Example for installed app
let appId: String = "111299000796"
// Example for web app
let appId: URL = URL(string: "http://yourwebapp.com")
let channelID: String = "com.samsung.multiscreen.helloworld"
let msApplication = service.createApplication(appID, channelURI: channelID, args: nil)
msApplication.connectionTimeout = 5.0
// Attributes is optional
let attr: [String:String] = ["userID":"idTest","userPW":"pwTest"]
// Connect to the tv application.
// Note: This will also launch the tv application if not already launched
msApplication.connect(attr)
// Disconnect from the application
msApplication.disconnect()
// Install the application on the TV.
// Note: This will only bring up the installation page on the TV.
// The user will still have to acknowledge by selecting "install" using the TV remote.
msApplication.install({ (success, error) -> Void in
if success == true {
print("Application.install Success")
} else {
print("Application.install Error : \(error)")
}
})
Sending Messages from a Mobile Application to a TV Application
Once your mobile application and TV application are connected, you can send messages to/from any or all clients connected including the TV.
For each message, you must supply a:
Message ID:
This is just a short string describing your message. example: “fireMissile”
Message Data:
This is any string containing the data for your message.
Message Target:
This can be one of the Message.TARGET constants or a Client or a list of Clients.
// parameter event: The event name
// parameter message: A JSON serializable message object
// parameter data: Any binary data to send with the message
// parameter target: The target recipient(s) of the message.Can be a string client id, a collection of ids or a string MessageTarget (like MessageTarget.All.rawValue)
let eventID: String = "fireMissile"
let msgData: [String : AnyObject] = ["speed" : "100" as Anyobject]
let binData: Data = Data(base64Encoded: image)
// Publish an event containing a text message payload
msApplication?.publish(event: eventID, message: msgDataas AnyObject?)
// Publish an event containing a text message and binary payload
msApplication?.publish(event: eventID, message: msgDataas AnyObject?, data: binData)
// Publish an event with text message payload to one or more targets
msApplication?.publish(event: eventID, message: msgDataas AnyObject?, target: MessageTarget.Host.rawValue as Anyobject)
// Publish an event containing a text message and binary payload to one or more targets
msApplication?.publish(event: eventID, message: msgDataas AnyObject?, data: binData, target: MessageTarget.Host.rawValue as Anyobject)
Receiving Messages in a Mobile Application
To receive incoming messages from another device, you need to add a message listener for messages that you expect to receive.
Received messages will include the message payload, and which client sent the message.
// MARK: - ChannelDelegate -
func onMessage(_ message: Message) {
// Called when the Channel receives a text message
printf("Message is received from \(message.from)")
if let data = message.data as? [String : AnyObject] {
}
}
func onData(_ message: Message, payload: Data) {
// Called when the Channel receives a binary data message
printf("Data is received from \(message.from)")
}
Delegate Protocol in a Mobile Application
There are several events that occur during the lifecycle of a Smart View application.
You can add listeners for any or all of them. Below are the recommended set of events to listen for.
// MARK: - ChannelDelegate -
func onConnect(_ client: ChannelClient?, error: NSError?){
// Called when the Channel is connected
}
func onReady() {
// Called when the host app is ready to send or receive messages
}
func onDisconnect(_ client: ChannelClient?, error: NSError?) {
// Called when the Channel is disconnected
}
func onMessage(_ message: Message) {
//Called when the Channel receives a text message
}
func onData(_ message: Message, payload: Data) {
// Called when the Channel receives a binary data message
}
func onClientConnect(_ client: ChannelClient) {
// Called when a client connects to the Channel
}
func onClientDisconnect(_ client: ChannelClient) {
// Called when a client disconnects from the Channel
}
func onError(_ error: NSError) {
// Called when a Channel Error is fired
}
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.