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:^{
}];
});
}
}
}
}];
}
}
标签:AVAILABLE,INUIEditVoiceShortcutViewController,void,Siri,NSLog,Shortcut,12.0,API 来源: https://www.cnblogs.com/cxxl/p/14648996.html