Closed Ezaldeen99 closed 2 years ago
@Ezaldeen99 which method does you use, and whats the error performance
I am trying to call the TYActivator method or the TYMessageCenter however nothing is happened after I call these two methods the doc. says that we should add TYSmartHomeDataProtocol before we use the BizBundle however, TYSmartHomeDataProtocol is deprecated and it says we should use TYFamilyProtocol instead and both are not working (nothing happens after we call the method.
let impl = TuyaSmartBizCore.sharedInstance().service(of: TYActivatorProtocol.self) as! TYActivatorProtocol
impl.gotoCategoryViewController()
impl.activatorCompletion(TYActivatorCompletionNode.normal, customJump: false, completionBlock: { (evIdList:[Any]?) in
print(evIdList ?? [])
})
currently there is no BizBundle swift demo that is working and this is why I can't find any reference for this issue.
controller can be seen here
import Foundation
import TuyaSmartDeviceKit
import TuyaSmartBizCore
import TYModuleServices
class HomeViewController: TuyaViewController, TuyaSmartHomeDelegate, TYSmartHomeDataProtocol, TYFamilyProtocol{
func getCurrentHome() -> TuyaSmartHome! {
let home = TuyaSmartHome.init(homeId: Home.current?.homeId ?? 111)
return home
}
func currentFamilyId() -> Int64 {
return Home.current?.homeId ?? 111
}
// to get devices list
private var home: TuyaSmartHome?
func initiateCurrentHome() {
tiles = [];
if Home.current != nil {
home = TuyaSmartHome(homeId: Home.current!.homeId)
home?.delegate = self
updateHomeDetail()
}
}
private func updateHomeDetail() {
home?.getDetailWithSuccess({ (model) in
self.initiateDevices()
}, failure: { [weak self] (error) in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: NSLocalizedString("Failed to Fetch Home", comment: ""), message: errorMessage)
})
}
func initiateDevices() {
let deviceList = home?.deviceList
deviceList?.forEach({ TuyaSmartDeviceModel in
tiles.append(TileViewController(title: TuyaSmartDeviceModel.name, online: TuyaSmartDeviceModel.isOnline, imageName: TuyaSmartDeviceModel.iconUrl , deviceId: TuyaSmartDeviceModel.devId))
})
layout()
}
let topSpacerView = UIView()
let headerView = HomeHeaderView()
let scrollView = UIScrollView()
let stackView = UIStackView()
var headerViewTopConstraint: NSLayoutConstraint?
var viewTopConstraint: NSLayoutConstraint?
var tiles :Array<TileViewController> = []
override func viewDidLoad() {
super.viewDidLoad()
style()
layout()
initiateCurrentHome()
TuyaSmartBizCore.sharedInstance().registerService(TYFamilyProtocol.self, withInstance: self)
TuyaSmartBizCore.sharedInstance().registerService(TYSmartHomeDataProtocol.self, withInstance: self)
}
func setupScrollView() {
scrollView.delegate = self
}
}
extension HomeViewController {
func style() {
navigationController?.navigationBar.isHidden = true
setTabBarImage(imageName: "1", title: "Home")
view.backgroundColor = .backgroundWhite
topSpacerView.backgroundColor = .mainColor
headerView.backgroundColor = .mainColor
topSpacerView.translatesAutoresizingMaskIntoConstraints = false
headerView.translatesAutoresizingMaskIntoConstraints = false
scrollView.translatesAutoresizingMaskIntoConstraints = false
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = 8
}
func layout() {
view.addSubview(topSpacerView)
view.addSubview(headerView)
view.addSubview(scrollView)
scrollView.addSubview(stackView)
for tile in tiles {
addChild(tile)
stackView.addArrangedSubview(tile.view)
tile.didMove(toParent: self)
}
headerView.addDeviceButton.addTarget(self, action: #selector(thumbsUpButtonPressed), for: .touchUpInside)
headerViewTopConstraint = headerView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
NSLayoutConstraint.activate([
topSpacerView.topAnchor.constraint(equalTo: view.topAnchor),
topSpacerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
topSpacerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
topSpacerView.heightAnchor.constraint(equalToConstant: 30),
headerViewTopConstraint!,
headerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
headerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
topSpacerView.heightAnchor.constraint(equalToConstant: 150),
scrollView.topAnchor.constraint(equalTo: headerView.bottomAnchor, constant: 8),
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8),
scrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
stackView.topAnchor.constraint(equalTo: scrollView.topAnchor),
stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
stackView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),
])
setupScrollView()
}
@objc func thumbsUpButtonPressed() {
//let messages = TuyaSmartBizCore.sharedInstance().service(of: TYMessageCenterProtocol.self) as! TYMessageCenterProtocol
//messages.gotoMessageCenterViewControllerWith(animated: true)
let impl = TuyaSmartBizCore.sharedInstance().service(of: TYActivatorProtocol.self) as! TYActivatorProtocol
impl.gotoCategoryViewController()
impl.activatorCompletion(TYActivatorCompletionNode.normal, customJump: false, completionBlock: { (evIdList:[Any]?) in
print(evIdList ?? [])
})
}
}
// MARK: Animating scrollView
extension HomeViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let y = scrollView.contentOffset.y
let swipingDown = y <= 0
let shouldSnap = y > 30
let labelHeight = headerView.greeting.frame.height + 70 // label + spacer (102)
UIView.animate(withDuration: 0.3) {
self.headerView.greeting.alpha = swipingDown ? 1.0 : 0.0
self.headerView.view.alpha = swipingDown ? 1.0 : 0.0
}
UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.3, delay: 0, options: [], animations: {
self.headerViewTopConstraint?.constant = shouldSnap ? -labelHeight : 0
self.view.layoutIfNeeded()
})
}
}
@Ezaldeen99 did use SceneDelegate,We don't support SceneDelegate yet,remove it and try again https://stackoverflow.com/questions/59006550/how-to-remove-scene-delegate-from-ios-application
@taojingGino
Thanks your solution worked, I would like to make a swift demo for BizBundle. does tuya accept other people contributions ?
since the swift BizBundle demo is not working, I am trying to add BizBundle support to this project.
the logs shows this after calling the add device categories
the BizBundle obj-c is working fine, but even when I add the obj-c implementation to this project it stops working but it is working fine in here https://github.com/tuya/tuya-bizbundle-ios-sdk-sample-objc
any ideas why it is not working in swift even after following the documentation steps ?