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.
Install iOS sender API libraries either manually or using CocoaPods (recommended). Both methods are described below:
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.
iOS SDK Library includes 2 types of framework.
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.
you 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
refer to : Stripping Unwanted Architectures From Dynamic Libraries In Xcode
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.
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.
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:
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.
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
// 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)") } })
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:
// 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)
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)") }
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 }