项目作者: aronnelson

项目描述 :
NSUserActivity for Siri Shortcut in Objective C
高级语言:
项目地址: git://github.com/aronnelson/objcCommander.git
创建时间: 2018-08-28T17:14:44Z
项目社区:https://github.com/aronnelson/objcCommander

开源协议:

下载


objcCommander

NSUserActivity for Siri Shortcut in Objective C

These are the steps to create a Siri Shortcut using Objective C. Very easy and quick on iOS12

1: Enable Siri in Capabilities tab of your project.

2: Add the Intents framework in the Linked Frameworks and Libraries tab. Under target->General

3: In the project plist, add an entry: NSUserActivityTypes with string = project bundle ID.activity name. For example: com.awesomeapps.myawesomeapp.myactivity

4: Create a NSUserActivity. Set two variables to true, setEligibleForSearch and setEligibleForPrediction. Make it current once.

This will make it available to Siri.

For example: (k_activityID is your bundle ID+activity name For example: com.awesomeapps.myawesomeapp.myactivity)

NSUserActivity *theActivity = [[NSUserActivity alloc]initWithActivityType:k_activityID];
theActivity.title = @”Run Me”;
[theActivity setEligibleForSearch:true];
[theActivity setEligibleForPrediction:true];
theActivity.persistentIdentifier = k_activityID;
theActivity.suggestedInvocationPhrase = @”Run Me”;
self.view.userActivity = theActivity;
[theActivity becomeCurrent];

5:Handle the activity in: -(BOOL)application:(UIApplication )application continueUserActivity:(NSUserActivity )userActivity restorationHandler:(void (^)(NSArray> * _Nullable))restorationHandler
You can query the userActivity.title to verify the activity.

if ([theActivity.title isEqualToString:k_activityID]){
// do the activity

  1. }

6: In settings app->Siri you will be able to see your Shorcuts and record a command to execute them.