Siri Shortcut

Siri ShortcutAppDelegate.

大家好,欢迎来到IT知识分享网。

Siri Shortcut

AppDelegate.m

Siri Shortcut

Siri Shortcut

Siri Shortcut

Siri Shortcut

//#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 *_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:^{

}];

});

}

}

}

}];

}

}

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/47667.html

(0)

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信