Last Updated on : 2024-08-19 07:18:46download
Tuya provides BizBundles for integrating third-party voice skills. Currently, UI BizBundles are available for Amazon Alexa and Google Assistant voice skills and UI pages.
A complete authorization process goes through four interfaces: pre-authorization, authorization confirmation, authorization completion, and accounting unlinking.
Tuya has developed a configuration plugin particularly for users to customize UI elements as needed. The following section describes the plugin and presents a demo.
enum ThingVoiceServiceType {
case amazonAlexa
case googleHome
}
public protocol ThingValueAddedServicePlugAPIProtocol {
optional func preAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func preAuthorizationImage(_ type: ThingVoiceServiceType) -> UIImage?
optional func preAuthorizationDetail(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func authorizationConfirmAppName(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmTipsDetail(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func didAuthorizationTitle(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationTipsDetail(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func authorizationUnbindTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindTipsDetails(_ type: ThingVoiceServiceType) -> [String]?
}
Three UI elements can be configured.
optional func preAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func preAuthorizationImage(_ type: ThingVoiceServiceType) -> UIImage?
optional func preAuthorizationDetail(_ type: ThingVoiceServiceType) -> String?
Five UI elements can be configured.
optional func authorizationConfirmIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func authorizationConfirmAppName(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationConfirmTipsDetail(_ type: ThingVoiceServiceType) -> String?
Four UI elements can be configured.
optional func didAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func didAuthorizationTitle(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationTipsDetail(_ type: ThingVoiceServiceType) -> String?
Four UI elements can be configured.
optional func authorizationUnbindIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func authorizationUnbindTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindTipsDetails(_ type: ThingVoiceServiceType) -> [String]?
Customize a new class to implement the protocol ThingValueAddedServicePlugAPIProtocol
:
import ThingValueAddedServicePlugAPI
class ThingValueAddedServicePlugAPIProtocolImpl: NSObject {
}
extension ThingValueAddedServicePlugAPIProtocolImpl: ThingValueAddedServicePlugAPIProtocol {
}
Register service:
ThingSmartBizCore.sharedInstance().registerService(ThingValueAddedServicePlugAPIProtocol.self, with: ThingValueAddedServicePlugAPIProtocolImpl.self)
Implement method as needed:
extension ThingValueAddedServicePlugAPIProtocolImpl: ThingValueAddedServicePlugAPIProtocol {
func preAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage? {
if (type == .amazonAlexa) {
return UIImage(named: "icon");
}else{
return UIImage(named: "bannerBanner");
}
}
func preAuthorizationImage(_ type: ThingVoiceServiceType) -> UIImage? {
if (type == .amazonAlexa) {
return UIImage(named: "banner");
}else{
return UIImage(named: "iconGoogle");
}
}
func preAuthorizationDetail(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "preAuthorizationDetail alexa";
}else{
return "preAuthorizationDetail google";
}
}
func authorizationConfirmIcon(_ type: ThingVoiceServiceType) -> UIImage? {
if (type == .amazonAlexa) {
return UIImage(named: "icon");
}else{
return UIImage(named: "iconGoogle");
}
}
func authorizationConfirmAppName(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa";
}else{
return "google";
}
}
func authorizationConfirmTitle(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa";
}else{
return "google";
}
}
func authorizationConfirmTipsTitle(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa tips";
}else{
return "google tips";
}
}
func authorizationConfirmTipsDetail(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa detail";
}else{
return "google detail";
}
}
func didAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage? {
if (type == .amazonAlexa) {
return UIImage(named: "icon");
}else{
return UIImage(named: "iconGoogle");
}
}
func didAuthorizationTitle(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa title";
}else{
return "google title";
}
}
func didAuthorizationTipsTitle(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa tips title";
}else{
return "google tips title";
}
}
func didAuthorizationTipsDetail(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa tips detail";
}else{
return "google tips detail";
}
}
func authorizationUnbindIcon(_ type: ThingVoiceServiceType) -> UIImage? {
if (type == .amazonAlexa) {
return UIImage(named: "icon");
}else{
return UIImage(named: "iconGoogle");
}
}
func authorizationUnbindTitle(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexa";
}else{
return "google";
}
}
func authorizationUnbindTipsTitle(_ type: ThingVoiceServiceType) -> String? {
if (type == .amazonAlexa) {
return "alexaTipsTitle";
}else{
return "googleTipsTitle";
}
}
func authorizationUnbindTipsDetails(_ type: ThingVoiceServiceType) -> [String]? {
if (type == .amazonAlexa) {
return ["authorizationUnbindTipsDetails"];
}else{
return ["authorizationUnbindTipsDetails", "authorizationUnbindTipsDetails"];
}
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback