Siri Shortcut
AppDelegate.m
//#pragma mark - INUIAddVoiceShortcutButtonDelegate
//新添加
- (void)presentAddVoiceShortcutViewController:(INUIAddVoiceShortcutViewController*)addVoiceShortcutViewControllerforAddVoiceShortcutButton:(INUIAddVoiceShortcutButton*)addVoiceShortcutButton API_AVAILABLE(ios(12.0)){
//新添加接口的代理
addVoiceShortcutViewController.delegate=self;
[selfpresentViewController:addVoiceShortcutViewControlleranimated:YEScompletion:nil];
}
#pragma mark -INUIEditVoiceShortcutViewControllerDelegate
//添加过,去编辑
- (void)presentEditVoiceShortcutViewController:(INUIEditVoiceShortcutViewController*)editVoiceShortcutViewControllerforAddVoiceShortcutButton:(INUIAddVoiceShortcutButton*)addVoiceShortcutButton API_AVAILABLE(ios(12.0)){
//编辑接口的代理
editVoiceShortcutViewController.delegate=self;
[selfpresentViewController:editVoiceShortcutViewControlleranimated:YEScompletion:nil];
}
#pragma mark - INUIAddVoiceShortcutViewControllerDelegate
- (void)addVoiceShortcutViewController:(INUIAddVoiceShortcutViewController*)controllerdidFinishWithVoiceShortcut:(nullableINVoiceShortcut*)voiceShortcuterror:(nullableNSError*)error API_AVAILABLE(ios(12.0)){
if(!error) {
NSLog(@"%@, %@", voiceShortcut.invocationPhrase, voiceShortcut.identifier);
[controllerdismissViewControllerAnimated:YES completion:^{
NSLog(@"添加成功");
}];
}else{
NSLog(@"%@", error.localizedDescription);
}
}
- (void)addVoiceShortcutViewControllerDidCancel:(INUIAddVoiceShortcutViewController*)controller API_AVAILABLE(ios(12.0)){
[controllerdismissViewControllerAnimated:YES completion:^{
NSLog(@"取消添加");
}];
}
- (void)editVoiceShortcutViewController:(INUIEditVoiceShortcutViewController*)controllerdidUpdateVoiceShortcut:(nullableINVoiceShortcut*)voiceShortcuterror:(nullableNSError*)error API_AVAILABLE(ios(12.0)){
if(!error) {
NSLog(@"%@, %@", voiceShortcut.invocationPhrase, voiceShortcut.identifier);
[controllerdismissViewControllerAnimated:YES completion:^{
NSLog(@"修改成功");
}];
}else{
NSLog(@"%@", error.localizedDescription);
}
}
- (void)editVoiceShortcutViewController:(INUIEditVoiceShortcutViewController *)controller didDeleteVoiceShortcutWithIdentifier:(NSUUID*)deletedVoiceShortcutIdentifier API_AVAILABLE(ios(12.0)){
[controllerdismissViewControllerAnimated:YES completion:^{
NSLog(@"删除命令");
}];
}
- (void)editVoiceShortcutViewControllerDidCancel:(INUIEditVoiceShortcutViewController*)controller API_AVAILABLE(ios(12.0)){
[controllerdismissViewControllerAnimated:YES completion:^{
NSLog(@"取消添加");
}];
}
//判断 可以自定义添加到Siri按钮
- (void)isVoiceShortcutExist {
//回调再子线程,如操作UI需要回到主线程
if(@available(iOS12.0, *)) {
[[INVoiceShortcutCentersharedCenter]getAllVoiceShortcutsWithCompletion:^(NSArray<invoiceshortcut*> *_NullablevoiceShortcuts,NSError*_Nullableerror) {
if(!error) {
for(INVoiceShortcut*shortcutinvoiceShortcuts) {
//存在
if ([shortcut.shortcut.userActivity.activityType isEqualToString:@"Imy.SiriShortcut"]) {
dispatch_async(dispatch_get_main_queue(), ^{
//添加一个按钮,可以点击跳转INUIEditVoiceShortcutViewController,INUIEditVoiceShortcutViewController需要自己生成
INUIEditVoiceShortcutViewController *editVC = [[INUIEditVoiceShortcutViewController alloc] initWithVoiceShortcut:shortcut];
editVC.delegate=self;
[selfpresentViewController:editVCanimated:YEScompletion:^{
}];
});
}else{
//不存在
dispatch_async(dispatch_get_main_queue(), ^{
//添加一个按钮,可以点击跳转INUIAddVoiceShortcutViewController,INUIAddVoiceShortcutViewController需要自己生成
INShortcut* shortCut = [[INShortcutalloc]initWithUserActivity:[selfcreateRelevantUserActivity]];
INUIAddVoiceShortcutViewController *addVC = [[INUIAddVoiceShortcutViewController alloc] initWithShortcut:shortCut];
addVC.delegate=self;
[selfpresentViewController:addVCanimated:YEScompletion:^{
}];
});
}
}
}
}];
}
}
Siri Shortcut的更多相关文章
- Eclipse CDT: Shortcut to switch between .h and .cpp
ctrl+ tab is the default shortcut.You can change it in Window → Preferences → General → Keys: Toggl ...
- 在iPhone上同时关闭语音控制和siri的方法
分享 步骤及要点:1.在设置里打开siri.语音控制就自动关闭了.2.在siri里的"仅语言拨号"语言项里选择"土耳其文"或者"阿拉伯文". ...
- 使用 Swift 在 iOS 10 中集成 Siri —— SiriKit 教程
下载 Xcode 8,配置 iOS 10 和 Swift 3 (可选)通过命令行编译 除 非你想使用命令行编译,使用 Swift 3.0 的工具链并不需要对项目做任何改变.如果你想的话,打开 Xcod ...
- android shortcut &livefoulder
android shortcut(实现步骤) 1.建立activity 2.minifest 里面注册并加上intent-filter,name为:android.intent.action.CREA ...
- 关于favicon.ico,shortcut icon,icon
引入一篇文章.关于favicon.ico二三事. http://www.cnblogs.com/LoveJenny/archive/2012/05/22/2512683.html 一直对favicon ...
- Linux Shell shortcut
Ctrl+a跳到第一个字符前Ctrl+x同上但再按一次会从新回到原位置 Details see below: Linux shell shortcut
- [转] Fix: Screen Clipping Shortcut In OneNote Not Working After Upgrading To Windows 8.1
RECOMMENDED: Click here to fix Windows errors and optimize system performance No doubt, OneNote is y ...
- Xcode Custom Shortcut
edit file "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources" add < ...
- Android添加快捷方式(Shortcut)到手机桌面
Android添加快捷方式(Short)到手机桌面 权限 要在手机桌面上添加快捷方式,首先需要在manifest中添加权限. <!-- 添加快捷方式 --> <uses-permis ...
- Django views 中的 shortcut function
shortcut function都在django.shortcuts这个包中,主要包含有:render(), render_to_response(), redirect(), get_object ...
随机推荐
- C# 8.0 中的 Disposable ref structs(可处置的 ref 结构)
官方文档中的解释: 用 ref 修饰符声明的 struct 可能无法实现任何接口,因此无法实现 IDisposable. 因此,要能够处理 ref struct,它必须有一个可访问的 void D ...
- JS中对DOM元素的操作
https://www.runoob.com/jquery/jquery-ref-html.html 1.each 遍历 //遍历所有class为checksingle的DOM元素 $(" ...
- 在博客中实现播放音乐功能(QQ,网易,酷狗,虾米,百度)
1.在页头head标签里添加: <link rel="stylesheet" href="https://static.likepoems.com/cdn/apla ...
- 论文笔记 - PRISM: A Rich Class of Parameterized Submodular Information Measures for Guided Subset Selection
Motivation 与 Active Learning 类似,Target Learning 致力于 挑选外卖更"感兴趣"的数据,即人为为更重要的数据添加 bias.例如我们当前 ...
- Linux操作系统,笔录!
1.Linux 1.1.Linux介绍: Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX ...
- springboot滚动分页展示列表(类似layui瀑布流效果)
背景: 公司项目要求获取用户关联的好友列表,要求分页查询,十条数据一页,滚动页面是点击加载更多,显示下一页列表. 示例图: 实现: 本项目采用的前端模板是freemaker,主要前端页面代码(没有 ...
- created与mounted执行顺序(关于微任务与宏任务)
1.ps:只要你只使用created或者mounted中的一个不就好了吗[dog].这样只要在第一个异步任务代码跳出前,嵌套第二个任务函数就好了 最后面的两个链接一个是微任务与宏任务的通俗例子,一个是 ...
- Java安全之CC4,5,7
前言 前边已经将CC链中的关键部分学习差不多,接下来就是一些扩展思路, CC4 ObjectInputStream.readObject() PriorityQueue.readObject() Pr ...
- Perl exists 函数和defined函数的区别
Perl exists 函数和defined函数的区别
- 833(DIV2)——C题题解
题目链接 题目大意: 给定n个数,你可以对数值为0的数改变其为任意值,问最后前缀和为0的个数的最大值. 思路: 这题比较可惜,自己的思路没有问题,但是他少了一些东西.对数组进行前缀和处理,我们可以发现 ...