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 {

? ? //回調(diào)再子線程,如操作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(), ^{

? ? ? ? ? ? ? ? ? ? ? ? ? ? //添加一個按鈕燃箭,可以點擊跳轉(zhuǎn)INUIEditVoiceShortcutViewController扰法,INUIEditVoiceShortcutViewController需要自己生成

? ? ? ? ? ? ? ? ? ? ? ? ? ? INUIEditVoiceShortcutViewController *editVC = [[INUIEditVoiceShortcutViewController alloc] initWithVoiceShortcut:shortcut];

? ? ? ? ? ? ? ? ? ? ? ? ? ? editVC.delegate=self;

? ? ? ? ? ? ? ? ? ? ? ? ? ? [selfpresentViewController:editVCanimated:YEScompletion:^{


? ? ? ? ? ? ? ? ? ? ? ? ? ? }];

? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? ? ? //不存在

? ? ? ? ? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? ? ? ? ? //添加一個按鈕净神,可以點擊跳轉(zhuǎn)INUIAddVoiceShortcutViewController,INUIAddVoiceShortcutViewController需要自己生成

? ? ? ? ? ? ? ? ? ? ? ? ? ? INShortcut* shortCut = [[INShortcutalloc]initWithUserActivity:[selfcreateRelevantUserActivity]];


? ? ? ? ? ? ? ? ? ? ? ? ? ? INUIAddVoiceShortcutViewController *addVC = [[INUIAddVoiceShortcutViewController alloc] initWithShortcut:shortCut];




? ? ? ? ? ? ? ? ? ? ? ? ? ? addVC.delegate=self;

? ? ? ? ? ? ? ? ? ? ? ? ? ? [selfpresentViewController:addVCanimated:YEScompletion:^{


? ? ? ? ? ? ? ? ? ? ? ? ? ? }];

? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }


? ? ? ? }];

? ? }

}


百度網(wǎng)盤:

鏈接: https://pan.baidu.com/s/1H1wJqVX9sJwakCtg9PSVig 提取碼: ddsd

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末齐唆,一起剝皮案震驚了整個濱河市遣铝,隨后出現(xiàn)的幾起案子拧烦,更是在濱河造成了極大的恐慌忘闻,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件恋博,死亡現(xiàn)場離奇詭異齐佳,居然都是意外死亡私恬,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進(jìn)店門炼吴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來本鸣,“玉大人,你說我怎么就攤上這事缺厉∮栏撸” “怎么了隧土?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵提针,是天一觀的道長。 經(jīng)常有香客問我曹傀,道長辐脖,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任皆愉,我火速辦了婚禮嗜价,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘幕庐。我一直安慰自己久锥,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布异剥。 她就那樣靜靜地躺著瑟由,像睡著了一般。 火紅的嫁衣襯著肌膚如雪冤寿。 梳的紋絲不亂的頭發(fā)上歹苦,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天,我揣著相機與錄音督怜,去河邊找鬼殴瘦。 笑死,一個胖子當(dāng)著我的面吹牛号杠,可吹牛的內(nèi)容都是我干的蚪腋。 我是一名探鬼主播,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼姨蟋,長吁一口氣:“原來是場噩夢啊……” “哼辣吃!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起芬探,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤神得,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后偷仿,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體哩簿,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡宵蕉,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了节榜。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片羡玛。...
    茶點故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖宗苍,靈堂內(nèi)的尸體忽然破棺而出稼稿,到底是詐尸還是另有隱情,我是刑警寧澤讳窟,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布让歼,位于F島的核電站,受9級特大地震影響丽啡,放射性物質(zhì)發(fā)生泄漏谋右。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一补箍、第九天 我趴在偏房一處隱蔽的房頂上張望改执。 院中可真熱鬧,春花似錦坑雅、人聲如沸辈挂。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽终蒂。三九已至,卻和暖如春蛹尝,著一層夾襖步出監(jiān)牢的瞬間后豫,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工突那, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留挫酿,地道東北人。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓愕难,卻偏偏與公主長得像早龟,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子猫缭,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容