Sevak Tadevosyan
Sevak Tadevosyan

Reputation: 21

Smart View SDK in Swift, how to connect to tv, and send key commands? what is channelId and appId?

I have implemented samsung remote control tv app in ios with swift, and have done every action manually, now want to switch to smart-view-sdk, at this moment I'm able to discover TVs in local network, next steps are: connectToTV(service: Service) launchApp(appId: String) sendKeyCommand(commandKey: String) and cast video/photo

here is my current code? can someone help me to do these steps, I have already read the documentation

here is my code:

import Foundation
import SmartView
import Network

class SamsungService: ServiceSearchDelegate, ObservableObject {
    
    @Published
    var services = [Service]()
    
    let serviceSearch = Service.search()
    var didFindServiceObserver: AnyObject? = nil
    var didRemoveServiceObserver: AnyObject? = nil
    
    init() {
        self.serviceSearch.start()
        listenForNotifications()
    }
    
    func connectTo(_ service: Service) {
        
    }

    func launchApp(_ appId: String, on service: Service) {
        
    }
    
    func sendCommand(_ command: String, to service: Service) {
        
    }
 
    func listenForNotifications() {
        didFindServiceObserver = NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: MSDidFindService), object: serviceSearch, queue: .main, using: { notification in
            guard let service = notification.userInfo?["service"] as? Service else { return }
            self.services.append(service)
        })
        
        didRemoveServiceObserver = NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: MSDidRemoveService), object: serviceSearch, queue: .main, using: { notification in
            let service = notification.userInfo?["service"] as? Service
            self.services.removeAll(where: { $0.id == service?.id })
        })
    }
}

Upvotes: 0

Views: 85

Answers (0)

Related Questions