使用Siri打开自己的应用并触发自己应用的呼叫视频或者语音功能

1.使用Siri这个功能,首先要引入SiriKit这个扩展程序(App Extension).

1.创建一个应用扩展.

在自己的项目下,通过 file->new->target->Intenst Extension. 而在next 后,Product name 设置扩展程序名字,Project选项看是自己的项目吗 ,Embed in Application 是不是自己的项目 如果都是那就点击finish完成.

Add an Intents App Extension to Your Project

Adding an Intents app extension target provides the initial files you need to build your Intents extension and configures your Xcode project to build that extension and include it in your app’s bundle.

Open your existing app project in Xcode.

Choose File > New > Target.

Select Intents extension from the Application Extension group of the iOS or watchOS platform.

Click Next.

Specify the name of your extension and configure the language and other options.

For an iOS app, enable the Include UI Extension option if you plan to customize portions of the Siri interface.

Click Finish.

Note

You may add more than one Intents extension to your app, but each extension must support different intents. Create multiple extensions only if doing so provides a performance advantage or reduces the memory footprint of each extension.

2.修改默认的Intens事件

Intens事件有

SiriKit groups intents into domains based on the type of app that is likely to support them.

Messaging
Send messages and search the user’s received messages.

Lists and Notes
Create and manage notes and to-do list items.

Workouts
Start, end, and manage fitness routines.

Payments
Send payments between users or pay bills.

VoIP Calling
Initiate calls and search the user’s call history.

Media
Provide media playback.

Visual Codes
Convey contact and payment information using Quick Response (QR) codes.

Photos
Search for and display photos.

Ride Booking
Book rides and report their status.

Car Commands
Manage vehicle door locks and get the vehicle’s status.

CarPlay
Interact with a vehicle’s CarPlay system.

Restaurant Reservations
Create and manage restaurant reservations with help from the Maps app.

需要使用到的是VoIp calling 域 的INStartVideoCallIntent INStartAudioCallIntent两个事件

将扩展程序的info.plist文件的NSExtension项 默认的IntentsSupported IntentsRestrictedWhileLocked改成这两个

并且还要设置Siri权限 Privacy - Siri Usage Description 和 Privacy - Speech Recognition Usage Description 权限 这两个权限最好也在主程序info.plist里设置一下.

3.IntentHnadler.m 里添加INStartVideoCallIntentHandling和INStartAudioCallIntentHandling

然后实现协议方法

#pragma mark - INStartVideoCallIntentHandling
//解决联系人
- (void)resolveContactsForStartVideoCall:(INStartVideoCallIntent *)intent withCompletion:(void (^)(NSArray<INPersonResolutionResult *> *resolutionResults))completion{//NSLog(@"呼叫视频:33333333");INPerson *peson = [[INPerson alloc] initWithPersonHandle:[[INPersonHandle alloc] initWithValue:@"志愿者" type:INPersonHandleTypeUnknown] nameComponents:nil displayName:@"志愿者" image:nil contactIdentifier:@"志愿者" customIdentifier:@"志愿者"];INPersonResolutionResult *result = [INPersonResolutionResult successWithResolvedPerson:peson];completion(@[result]);
}
//
- (void)confirmStartVideoCall:(INStartVideoCallIntent *)intent completion:(void (^)(INStartVideoCallIntentResponse *response))completion{//NSLog(@"呼叫视频:22222222");NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INStartVideoCallIntent class])];userActivity.title = @"志愿者";userActivity.keywords = [NSSet setWithArray:@[@"测试人员", @"测试", @"测试"]];userActivity.eligibleForHandoff = YES;userActivity.eligibleForSearch = YES;INStartVideoCallIntentResponse *response = [[INStartVideoCallIntentResponse alloc] initWithCode:INStartVideoCallIntentResponseCodeReady userActivity:userActivity];completion(response);
}
- (void)handleStartVideoCall:(INStartVideoCallIntent *)intent completion:(void (^)(INStartVideoCallIntentResponse *response))completion{//NSLog(@"呼叫视频:11111111");NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INStartVideoCallIntent class])];userActivity.title = @"测试";userActivity.keywords = [NSSet setWithArray:@[@"测试", @"测试", @"测试"]];userActivity.eligibleForHandoff = YES;userActivity.eligibleForSearch = YES;INStartVideoCallIntentResponse *response = [[INStartVideoCallIntentResponse alloc] initWithCode:INStartVideoCallIntentResponseCodeContinueInApp userActivity:userActivity];completion(response);
}#pragma mark - INStartAudioCallIntentHandling
- (void)resolveContactsForStartAudioCall:(INStartAudioCallIntent *)intent withCompletion:(void (^)(NSArray<INPersonResolutionResult *> *resolutionResults))completion{//NSLog(@"呼叫电话:33333333");INPerson *peson = [[INPerson alloc] initWithPersonHandle:[[INPersonHandle alloc] initWithValue:@"测试" type:INPersonHandleTypeUnknown] nameComponents:nil displayName:@"测试" image:nil contactIdentifier:@"测试" customIdentifier:@"测试"];INPersonResolutionResult *result = [INPersonResolutionResult successWithResolvedPerson:peson];completion(@[result]);
}
- (void)confirmStartAudioCall:(INStartAudioCallIntent *)intent completion:(void (^)(INStartAudioCallIntentResponse *response))completion{//NSLog(@"呼叫电话:22222222");NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INStartVideoCallIntent class])];userActivity.title = @"测试";userActivity.keywords = [NSSet setWithArray:@[@"测试", @"测试", @"测试"]];userActivity.eligibleForHandoff = YES;userActivity.eligibleForSearch = YES;INStartAudioCallIntentResponse *response = [[INStartAudioCallIntentResponse alloc] initWithCode:INStartAudioCallIntentResponseCodeReady userActivity:userActivity];completion(response);
}
//
- (void)handleStartAudioCall:(INStartAudioCallIntent *)intent completion:(void (^)(INStartAudioCallIntentResponse *response))completion{//NSLog(@"呼叫电话:11111111");NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INStartVideoCallIntent class])];userActivity.title = @"测试";userActivity.keywords = [NSSet setWithArray:@[@"测试", @"测试", @"测试"]];userActivity.eligibleForHandoff = YES;userActivity.eligibleForSearch = YES;INStartAudioCallIntentResponse *response = [[INStartAudioCallIntentResponse alloc] initWithCode:INStartAudioCallIntentResponseCodeContinueInApp userActivity:userActivity];completion(response);
}

4.权限设置

#import <Intents/Intents.h>//Siriif (@available(iOS 10.0, *)) {[INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) {switch (status) {case INSiriAuthorizationStatusNotDetermined:NSLog(@"用户尚未对该应用程序作出选择。");break;case INSiriAuthorizationStatusRestricted:NSLog(@"此应用程序无权使用Siri服务");break;case INSiriAuthorizationStatusDenied:NSLog(@"用户已明确拒绝此应用程序的授权");break;case INSiriAuthorizationStatusAuthorized:NSLog(@"用户可以使用此应用程序的授权");break;default:break;}}];} else {// Fallback on earlier versions}

5.在主程序也就是AppDelegate里调用回调监听这个事件


- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{NSLog(@"视频呼叫:触发了%@",userActivity.title);return YES;
}

6.出现不在通讯录事件,首先查看扩展程序target版本应该设置低一些不超出

iOS Siri调用自己应用的视频呼叫功能相关推荐

  1. ios通过webrtc实现微信的视频对讲功能

    微信的视频对讲主要是通过webrtc中点对点的形式实现的(也就是p2p),主要的原理如下图: 实现是站在巨人的肩膀上实现的:https://github.com/Xianlau/WebRTC_Demo ...

  2. IOS视频编辑功能详解上篇-添加水印

    前言 用代码在简单视频编辑中,主要就是加美颜.水印(贴图).视频截取.视频拼接.音视频的处理,在美颜中,使用GPUImage即可实现多种滤镜.磨皮美颜的功能,并且可以脸部识别实时美颜等功能,这个有很多 ...

  3. android视频分享功能吗,Unity 调用 Android 分享功能(基于ShareRec SDK视频分享)

    需求 Mob 平台是一个强大的提供分享功能的平台,为移动开发者提供 ShareSDK 社交分享.ShareREC 手游录像分享.短信验证码 SDK 及 BigApp 等免费服务. Unity 使用 S ...

  4. IOS开发调用系统相机和打开闪光灯

    IOS开发调用系统相机和打开闪光灯      今天给大家分享一下如何调用iphone的拍照功能和打开闪光灯,有些代码我也不太理解,很多是在网上借鉴其他人的.IOS有两种的拍照和视频的方式:1.直接使用 ...

  5. IOS:批量导入图片和视频到模拟器的相册

    批量导入图片和视频到模拟器的相册 IOS开发中我们经常会用到模拟器调试,模拟器有个主要的好处就是程序启动块,最重要的是如果没有证书的话,我们就只能在模拟器上调试了.使用模拟器调试时我们可能碰到需要从系 ...

  6. Kurento应用开发指南(以Kurento 5.0为模板) 之四:示例教程 一对一视频呼叫

    5.3 教程四-一对一的视频呼叫 这个页面应用程序使用WebRTC技术实现了一个一对一的呼叫,换言话说,这个应用提供了一个简单的视频电话 5.3.1 运行示例程序 运行这个DEMO之前,你需要先安装K ...

  7. iOS开发系列-音频、视频以及摄像

    --iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...

  8. java录制视频_javacv开发详解之1:调用本机摄像头视频(建议使用javaCV最新版本)...

    javaCV系列文章: ' i# f% S' a# J9 X! w- g) wjavacv开发详解之1:调用本机摄像头视频 4 r' C, [4 ?' M7 Y; }javaCV开发详解之2:推流器实 ...

  9. 视频直播点播平台EasyDSS如何通过接口调用实现截取视频的功能?

    EasyDSS互联网视频云平台可供一站式的视频转码.点播.直播.推拉流.时移回放等服务,也能支持4K视频的直播.点播等功能,可应用在AR.VR.无人机推流.虚拟直播.教育培训.远程会议等场景中.为了便 ...

最新文章

  1. 75道常见AI面试题,看看你的知识盲点在哪?(附解析)
  2. 西藏最大云计算数据中心明年投入试运营
  3. Python爬虫开发教程,一看就懂!
  4. 数据结构与算法--代码鲁棒性案例分析
  5. C语言从入门到放弃视频教程
  6. Java工程师成神之路(2019正式版)
  7. CnOpenData中国高新技术企业专利统计数据
  8. 记忆测试系统java代码_JAVA课程设计——记忆测试系统(附源程序).doc
  9. PixelMe怎么使用?一文教你制作像素风图片
  10. 【android】高仿京东商城App,集成react-native热更功能
  11. c语言提供了三种预处理命令,C语言提供的三种预处理命令
  12. 新书推荐 |《用户增长方法论:找到产品长盛不衰的增长曲线》
  13. 北京信息科技大学第十一届程序设计竞赛(重现赛)
  14. 小巧高效的php框架,猿团YTFramework框架上线 让PHP开发更简单高效
  15. windows server 2008搭建nfs共享服务
  16. 服务器怎么和网站接入,网站服务器的带宽怎么接入呢?
  17. mysql handlersocket_HandlerSocket
  18. 网络营销的特点和优势
  19. OpenCV 图像特征提取——Harris角点检测
  20. 认真学习MySQL中的MVCC机制

热门文章

  1. 如何使用Eclipse打开已有工程听语音
  2. 为创造者而生——Unite Beijing 2018 Keynote回顾
  3. 微博报错:Ip Limit, request ip is not contained in safety ip error_code:10004/2/status
  4. VTL(Velocity Templates Language,即Velocity模板语言)初识语法总结
  5. Environment.SpecialFolder的值的含义(本地打印)
  6. 动态规划(3):最长非递减子序列
  7. 离线数据系统之MapReduce加强
  8. 数据库原理—数据查询
  9. android开发之应用Crash自动抓取Log_自动保存崩溃日志到本地
  10. 手机网页视频背景自动播放记录