更新时间:2024-08-07 02:44:19下载pdf
目前,三方语音技能业务包里,带界面的三方语音开放技能有 Amazon Alexa 和 Google Assistant。
完整的授权流程包含 4 个界面:授权前、授权确认、授权完成和解绑授权。
考虑到部分用户需要自定义 UI 元素,涂鸦特意新增了配置插件,来满足要求。下文将介绍该插件,并编写一个简单的 Demo 来实现 UI 元素的自定义。
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]?
}
授权前界面可以配置 3 个 UI 元素。
optional func preAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func preAuthorizationImage(_ type: ThingVoiceServiceType) -> UIImage?
optional func preAuthorizationDetail(_ type: ThingVoiceServiceType) -> String?
授权确认界面可以配置 5 个 UI 元素。
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?
授权完成界面可以配置 4 个 UI 元素。
optional func didAuthorizationIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func didAuthorizationTitle(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func didAuthorizationTipsDetail(_ type: ThingVoiceServiceType) -> String?
授权解绑界面可以配置 4 个 UI 元素。
optional func authorizationUnbindIcon(_ type: ThingVoiceServiceType) -> UIImage?
optional func authorizationUnbindTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindTipsTitle(_ type: ThingVoiceServiceType) -> String?
optional func authorizationUnbindTipsDetails(_ type: ThingVoiceServiceType) -> [String]?
定义一个新的类,通过该类实现 ThingValueAddedServicePlugAPIProtocol
协议:
import ThingValueAddedServicePlugAPI
class ThingValueAddedServicePlugAPIProtocolImpl: NSObject {
}
extension ThingValueAddedServicePlugAPIProtocolImpl: ThingValueAddedServicePlugAPIProtocol {
}
注册服务:
ThingSmartBizCore.sharedInstance().registerService(ThingValueAddedServicePlugAPIProtocol.self, with: ThingValueAddedServicePlugAPIProtocolImpl.self)
按需实现方法:
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"];
}
}
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈