【发布时间】:2016-06-20 02:54:26
【问题描述】:
我在 wwdc 中观看了 SiriKit 并阅读了文档。
仅当您的应用实现以下其中一项时才添加 SiriKit 支持 服务类型:
- 音频或视频通话
- 消息支付
- 搜索照片
- 锻炼
- 行程预订
我仍然想知道我是否可以为其他服务做(因为我的应用程序将用于企业应用程序)。
我的服务将是非常简单的搜索,例如“Find SQ212 in myapp”。
可以吗?我担心 sirkit 无法支持其他服务的意图。
【问题讨论】:
我在 wwdc 中观看了 SiriKit 并阅读了文档。
仅当您的应用实现以下其中一项时才添加 SiriKit 支持 服务类型:
- 音频或视频通话
- 消息支付
- 搜索照片
- 锻炼
- 行程预订
我仍然想知道我是否可以为其他服务做(因为我的应用程序将用于企业应用程序)。
我的服务将是非常简单的搜索,例如“Find SQ212 in myapp”。
可以吗?我担心 sirkit 无法支持其他服务的意图。
【问题讨论】:
不,你不能。这就是为什么它说“仅当您的应用实现以下类型的服务之一”。
你不会得到'find foo in bar'语法;每个相应的服务都有自己的语法 - 例如“在 MyApp 中开始锻炼”或“使用 MyApp 预订前往place 的旅程”。有关示例,请参阅https://developer.apple.com/sirikit/。
我希望使用 SiriKit API 的解决方法会导致您的应用在提交到一般应用商店时被拒绝,并且如果它通过 App Review 或没有通过,我希望它非常脆弱一开始就不要经历它。
【讨论】:
我发现 this article 在 swifting.io 上制作非 Apple 默认提供的 Sirikit 扩展。
使用 INVocabulary
来自 Apple 文档:
INVocabulary 对象可让您使用应用程序和应用程序当前用户独有的术语来扩充应用程序的固定词汇表。注册自定义术语为 Siri 提供了将这些术语适当地应用于相应意图对象所需的提示。您只能注册特定类型的自定义条款,例如联系人姓名、用户锻炼名称、应用于照片的自定义标签或用户特定的付款类型。
public enum INVocabularyStringType : Int {
case contactName
case contactGroupName
case photoTag
case photoAlbumName
case workoutActivityName
case carProfileName
}
INMessage
他们在这里使用 INSearchForMessagesIntent 设置索引搜索以寻找支持。
struct SupportMe{
static let systems = [
INPerson(personHandle: INPersonHandle(value: "MyNotes",
type: INPersonHandleType.unknown),
nameComponents: nil,
displayName: "MyNotes",
image: nil,
contactIdentifier: "MyNotes",
customIdentifier: "MyNotes")]
static let articles = [
INMessage(identifier: "MyNotesPassword",
content: "Retrieving password in MyNotes app. To retrieve
password use 'forgot password' button that is located below
sign in button. Then type email address that your account has
been assigned to and press reset password",
dateSent: Date(),
sender: SupportMe.systems[0],
recipients: [SupportMe.systems[0]])]
}
extension IntentHandler: INSearchForMessagesIntentHandling{
func handle(searchForMessages intent: INSearchForMessagesIntent,
completion: (INSearchForMessagesIntentResponse) -> Void){
let userActivity = NSUserActivity(activityType: String(INSearchForMessagesIntent.self))
let response = INSearchForMessagesIntentResponse(code: .success,
userActivity: userActivity)
response.messages = [SupportMe.articles[0]]
completion(response)
}
}
【讨论】: