IOS Siri和快捷指令打开app

server/2024/10/18 6:00:21/

使用场景
需要Siri打开应用或者在自定义快捷指令打开应用,并携带内容进入应用。

1.创建Intents文件
1.1 依次点开File->New->File

在这里插入图片描述

SiriKit_Intent_Definition_File_6">1.2 搜索intent关键字找到 SiriKit Intent Definition File文件

在这里插入图片描述在这里插入图片描述

1.3 找到刚才创建的Intent文件,点击+然后New Intent

在这里插入图片描述

1.4 LaunchApp根据自己需要来自定义命名

在这里插入图片描述

1.5 设置失败和成功提示内容

在这里插入图片描述

1.6 设置参数(这里设置了一个名为content的属性,可以根据自己需求添加)

在这里插入图片描述

1.7 设置输出content属性

在这里插入图片描述

2.创建一个Intent Extension的Targets
2.1 File->New->Targets

在这里插入图片描述

2.2 找到Intent Extension并创建

在这里插入图片描述

2.3 创建Intent Extension

在这里插入图片描述

2.4 配置Intent Extension到Intents

创建之后可以在项目里面看到
在这里插入图片描述
找到我们前面配置的Intents文件,关联Intent Extension
在这里插入图片描述

2.5 配置IntenHandler.m

导入#import “LaunchAppIntent.h”,关联LaunchAppIntentHandling
在这里插入图片描述
实现LaunchAppIntent的函数
在这里插入图片描述

- (void)handleLaunchApp:(nonnull LaunchAppIntent *)intent completion:(nonnull void (^)(LaunchAppIntentResponse * _Nonnull))completion {NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([LaunchAppIntent class])];completion([[LaunchAppIntentResponse alloc] initWithCode:LaunchAppIntentResponseCodeContinueInApp userActivity:userActivity]);
}- (void)confirmLaunchApp:(LaunchAppIntent *)intent completion:(void (^)(LaunchAppIntentResponse * _Nonnull))completion {NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([LaunchAppIntent class])];LaunchAppIntentResponse *response = [[LaunchAppIntentResponse alloc] initWithCode:LaunchAppIntentResponseCodeReady userActivity:userActivity];completion(response);
}- (void)resolveContentForLaunchApp:(nonnull LaunchAppIntent *)intent withCompletion:(nonnull void (^)(INStringResolutionResult * _Nonnull))completion {if (intent.content != nil && intent.content.length > 0) {completion([INStringResolutionResult successWithResolvedString:intent.content]);} else {completion([INStringResolutionResult needsValue]);}
}

resolveContentForLaunchApp:是你1.6步骤创建的参数content属性,用于代理接收传过来的参数内容。
如果你不走代理模式是不会走这里的,而是会走AppDelegate的application。

2.6 非代理模式下配置AppDelegate的application。
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {if([userActivity.interaction.intent isKindOfClass:[LaunchAppIntent class]]){INInteraction *interaction = userActivity.interaction;LaunchAppIntent *intent = (LaunchAppIntent *)interaction.intent;NSLog(@"application========================%@",intent.content);// 做自己的业务逻辑return YES;
}
3.配置info.plist
<key>NSSiriUsageDescription</key><string>使用Siri控制应用</string><key>NSUserActivityTypes</key><array><string>LaunchAppIntent</string></array>
4.调试
4.1 在快捷指令中添加我们的快捷指令

在这里插入图片描述

4.2 输入Launch App

在这里插入图片描述

4.3 输入我们需要带进入的属性内容(流程也就结束了)

在这里插入图片描述

5.可能出现的错误
5.1 Cycle inside Runner; building could produce unreliable results. This usually can be resolved by moving the shell script phase ‘Thin Binary’ so that it runs before the build phase that depends on its outputs.在这里插入图片描述

Thin Binary执行时机,必须在Copy Bundle Resources和Embed Foundation Extensions执行完成之后。


http://www.ppmy.cn/server/116957.html

相关文章

C#复习之内部类和分布类

知识点一&#xff1a;内部类 知识点二&#xff1a;分布类 知识点三&#xff1a;分部方法

《2024中国数据要素产业图谱2.0版》重磅发布

数据猿出品 本次“数据猿2024年度三大媒体策划活动——《2024中国数据要素产业图谱2.0版》”的发布&#xff0c;下一次版本迭代将于2024年12月底发布2024年3.0版&#xff0c;敬请期待&#xff0c;欢迎报名。 大数据产业创新服务媒体 ——聚焦数据 改变商业 随着技术不断革新&a…

[数据集][目标检测]乱堆物料检测数据集VOC+YOLO格式1143张1类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;1143 标注数量(xml文件个数)&#xff1a;1143 标注数量(txt文件个数)&#xff1a;1143 标注…

Mysql 的查询过慢如何排查以及优化

1.慢查询: (1).查看慢查询的日志文件有没有打开&#xff1a;show variables like ‘slow_query_log’; (2).因为默认是没有开启的所以一般我们需要手动的去开启&#xff1a;set global slow_query_logon; (3).查看慢查询的时间&#xff1a;show variables like ‘…

【BUG报错已解决】`ERROR: Failed building wheel for jupyter-nbextensions-configurator`

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《C干货基地》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 文章目录 前言一、问题描述1.1 报错示例1.2 报错分析1.3 解决思路 二、解决方法2.1 方法一&#xff1a;安装编译工具和依赖项2.…

【LeetCode】2552. 统计上升四元组

给你一个长度为 n 下标从 0 开始的整数数组 nums &#xff0c;它包含 1 到 n 的所有数字&#xff0c;请你返回上升四元组的数目。 如果一个四元组 (i, j, k, l) 满足以下条件&#xff0c;我们称它是上升的&#xff1a; 0 < i < j < k < l < n 且 nums[i] <…

从GreaterWMS学习仓库管理系统

前言 客户并不知道&#xff08;确切地&#xff09;他们需要什么&#xff1f; 需要通过需求分析工具和技术&#xff0c;利用宽进严出的需求池&#xff0c;需求验证使用原型测试&#xff0c;场景分析&#xff0c;专家评审&#xff0c;交叉检查等手段&#xff0c;经过充分验证的需…

停车场小程序如何实现分账功能?

智慧停车平台为什么迫切需要分账功能的原因&#xff0c;通过清结算系统提供的服务商分账功能&#xff0c;可以有效提高交易环节的分账效率。平台方只需要在后台配置好与各服务商、业主等多方分账规则&#xff0c;待交易订单形成后&#xff0c;清结算系统会自动化分账&#xff0…