Register multiple Siri shortcut at once
I wrote some code which try to register multiple Siri shortcut at once by iterating enum values
When I run the code and open settings app, it only shows the last registered shortcut.
How should I register multiple Siri shortcut at once?
static func registerSiriShortcut(to responder: UIResponder) {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
responder.userActivity = activity
responder.userActivity?.becomeCurrent()
}
}
}
ios swift ios12 siri sirishortcuts
add a comment |
I wrote some code which try to register multiple Siri shortcut at once by iterating enum values
When I run the code and open settings app, it only shows the last registered shortcut.
How should I register multiple Siri shortcut at once?
static func registerSiriShortcut(to responder: UIResponder) {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
responder.userActivity = activity
responder.userActivity?.becomeCurrent()
}
}
}
ios swift ios12 siri sirishortcuts
I am having the same problem as you, could you solve it?
– Sergio
Nov 22 '18 at 10:22
add a comment |
I wrote some code which try to register multiple Siri shortcut at once by iterating enum values
When I run the code and open settings app, it only shows the last registered shortcut.
How should I register multiple Siri shortcut at once?
static func registerSiriShortcut(to responder: UIResponder) {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
responder.userActivity = activity
responder.userActivity?.becomeCurrent()
}
}
}
ios swift ios12 siri sirishortcuts
I wrote some code which try to register multiple Siri shortcut at once by iterating enum values
When I run the code and open settings app, it only shows the last registered shortcut.
How should I register multiple Siri shortcut at once?
static func registerSiriShortcut(to responder: UIResponder) {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
responder.userActivity = activity
responder.userActivity?.becomeCurrent()
}
}
}
ios swift ios12 siri sirishortcuts
ios swift ios12 siri sirishortcuts
asked Nov 1 '18 at 6:18
Bigair
325413
325413
I am having the same problem as you, could you solve it?
– Sergio
Nov 22 '18 at 10:22
add a comment |
I am having the same problem as you, could you solve it?
– Sergio
Nov 22 '18 at 10:22
I am having the same problem as you, could you solve it?
– Sergio
Nov 22 '18 at 10:22
I am having the same problem as you, could you solve it?
– Sergio
Nov 22 '18 at 10:22
add a comment |
1 Answer
1
active
oldest
votes
Your code seems okay to me. Generally, Settings->Siri shows only the recent registered shortcuts. If you go to Settings->Siri->All shortcuts, you will see the all names there.
As you mention in your code activity.isEligibleForSearch = true Alternatively, go to your phone search from swipe right from home and type the shortcut, you should see the shortcut item's popup too.
EDIT 1: Proof of my Code:
Info.plist: You need to mention how many NSUserActivityTypes:
<Key>NSUserActivityTypes</key>
<array>
<string>com.rio.SiriShortcuts.makeGreen</string>
<string>com.rio.SiriShortcuts.makeRed</string>
</array>
Enum class:
enum SiriShortcutType {
case makeRed
case makeGreen
var siriActivityType: String {
switch self {
case .makeRed:
return "com.rio.SiriShortcuts.makeRed"
case .makeGreen:
return "com.rio.SiriShortcuts.makeGreen"
}
}
var siriShortcutTitle: String {
switch self {
case .makeRed:
return "Make View Red"
case .makeGreen:
return "Make View Green"
}
}
var color: String {
switch self {
case .makeRed:
return "red"
case .makeGreen:
return "green"
}
}
static let allCases:[SiriShortcutType] = [.makeRed, .makeGreen]
}
Now my register method in VC (called by button action):
func registerSiriShortcut() {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
var suggestions: [INShortcut] =
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.userInfo = ["color" : type.color]
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(type.siriActivityType)
suggestions.append(INShortcut(userActivity: activity))
}
INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions)
}
}
Edit 1: INShortcut supports multiple Siri Shortcuts: See the updated registerSiriShortcut().
1
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
1
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
1
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
1
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
1
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
|
show 10 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53096110%2fregister-multiple-siri-shortcut-at-once%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code seems okay to me. Generally, Settings->Siri shows only the recent registered shortcuts. If you go to Settings->Siri->All shortcuts, you will see the all names there.
As you mention in your code activity.isEligibleForSearch = true Alternatively, go to your phone search from swipe right from home and type the shortcut, you should see the shortcut item's popup too.
EDIT 1: Proof of my Code:
Info.plist: You need to mention how many NSUserActivityTypes:
<Key>NSUserActivityTypes</key>
<array>
<string>com.rio.SiriShortcuts.makeGreen</string>
<string>com.rio.SiriShortcuts.makeRed</string>
</array>
Enum class:
enum SiriShortcutType {
case makeRed
case makeGreen
var siriActivityType: String {
switch self {
case .makeRed:
return "com.rio.SiriShortcuts.makeRed"
case .makeGreen:
return "com.rio.SiriShortcuts.makeGreen"
}
}
var siriShortcutTitle: String {
switch self {
case .makeRed:
return "Make View Red"
case .makeGreen:
return "Make View Green"
}
}
var color: String {
switch self {
case .makeRed:
return "red"
case .makeGreen:
return "green"
}
}
static let allCases:[SiriShortcutType] = [.makeRed, .makeGreen]
}
Now my register method in VC (called by button action):
func registerSiriShortcut() {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
var suggestions: [INShortcut] =
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.userInfo = ["color" : type.color]
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(type.siriActivityType)
suggestions.append(INShortcut(userActivity: activity))
}
INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions)
}
}
Edit 1: INShortcut supports multiple Siri Shortcuts: See the updated registerSiriShortcut().
1
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
1
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
1
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
1
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
1
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
|
show 10 more comments
Your code seems okay to me. Generally, Settings->Siri shows only the recent registered shortcuts. If you go to Settings->Siri->All shortcuts, you will see the all names there.
As you mention in your code activity.isEligibleForSearch = true Alternatively, go to your phone search from swipe right from home and type the shortcut, you should see the shortcut item's popup too.
EDIT 1: Proof of my Code:
Info.plist: You need to mention how many NSUserActivityTypes:
<Key>NSUserActivityTypes</key>
<array>
<string>com.rio.SiriShortcuts.makeGreen</string>
<string>com.rio.SiriShortcuts.makeRed</string>
</array>
Enum class:
enum SiriShortcutType {
case makeRed
case makeGreen
var siriActivityType: String {
switch self {
case .makeRed:
return "com.rio.SiriShortcuts.makeRed"
case .makeGreen:
return "com.rio.SiriShortcuts.makeGreen"
}
}
var siriShortcutTitle: String {
switch self {
case .makeRed:
return "Make View Red"
case .makeGreen:
return "Make View Green"
}
}
var color: String {
switch self {
case .makeRed:
return "red"
case .makeGreen:
return "green"
}
}
static let allCases:[SiriShortcutType] = [.makeRed, .makeGreen]
}
Now my register method in VC (called by button action):
func registerSiriShortcut() {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
var suggestions: [INShortcut] =
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.userInfo = ["color" : type.color]
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(type.siriActivityType)
suggestions.append(INShortcut(userActivity: activity))
}
INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions)
}
}
Edit 1: INShortcut supports multiple Siri Shortcuts: See the updated registerSiriShortcut().
1
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
1
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
1
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
1
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
1
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
|
show 10 more comments
Your code seems okay to me. Generally, Settings->Siri shows only the recent registered shortcuts. If you go to Settings->Siri->All shortcuts, you will see the all names there.
As you mention in your code activity.isEligibleForSearch = true Alternatively, go to your phone search from swipe right from home and type the shortcut, you should see the shortcut item's popup too.
EDIT 1: Proof of my Code:
Info.plist: You need to mention how many NSUserActivityTypes:
<Key>NSUserActivityTypes</key>
<array>
<string>com.rio.SiriShortcuts.makeGreen</string>
<string>com.rio.SiriShortcuts.makeRed</string>
</array>
Enum class:
enum SiriShortcutType {
case makeRed
case makeGreen
var siriActivityType: String {
switch self {
case .makeRed:
return "com.rio.SiriShortcuts.makeRed"
case .makeGreen:
return "com.rio.SiriShortcuts.makeGreen"
}
}
var siriShortcutTitle: String {
switch self {
case .makeRed:
return "Make View Red"
case .makeGreen:
return "Make View Green"
}
}
var color: String {
switch self {
case .makeRed:
return "red"
case .makeGreen:
return "green"
}
}
static let allCases:[SiriShortcutType] = [.makeRed, .makeGreen]
}
Now my register method in VC (called by button action):
func registerSiriShortcut() {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
var suggestions: [INShortcut] =
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.userInfo = ["color" : type.color]
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(type.siriActivityType)
suggestions.append(INShortcut(userActivity: activity))
}
INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions)
}
}
Edit 1: INShortcut supports multiple Siri Shortcuts: See the updated registerSiriShortcut().
Your code seems okay to me. Generally, Settings->Siri shows only the recent registered shortcuts. If you go to Settings->Siri->All shortcuts, you will see the all names there.
As you mention in your code activity.isEligibleForSearch = true Alternatively, go to your phone search from swipe right from home and type the shortcut, you should see the shortcut item's popup too.
EDIT 1: Proof of my Code:
Info.plist: You need to mention how many NSUserActivityTypes:
<Key>NSUserActivityTypes</key>
<array>
<string>com.rio.SiriShortcuts.makeGreen</string>
<string>com.rio.SiriShortcuts.makeRed</string>
</array>
Enum class:
enum SiriShortcutType {
case makeRed
case makeGreen
var siriActivityType: String {
switch self {
case .makeRed:
return "com.rio.SiriShortcuts.makeRed"
case .makeGreen:
return "com.rio.SiriShortcuts.makeGreen"
}
}
var siriShortcutTitle: String {
switch self {
case .makeRed:
return "Make View Red"
case .makeGreen:
return "Make View Green"
}
}
var color: String {
switch self {
case .makeRed:
return "red"
case .makeGreen:
return "green"
}
}
static let allCases:[SiriShortcutType] = [.makeRed, .makeGreen]
}
Now my register method in VC (called by button action):
func registerSiriShortcut() {
if #available(iOS 12.0, *) {
let cases = SiriShortcutType.allCases
var suggestions: [INShortcut] =
for type in cases {
let activity = NSUserActivity(activityType: type.siriActivityType)
activity.userInfo = ["color" : type.color]
activity.title = type.siriShortcutTitle
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(type.siriActivityType)
suggestions.append(INShortcut(userActivity: activity))
}
INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions)
}
}
Edit 1: INShortcut supports multiple Siri Shortcuts: See the updated registerSiriShortcut().
edited Nov 22 '18 at 20:13
answered Nov 1 '18 at 8:41
Razib Mollick
1,1191611
1,1191611
1
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
1
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
1
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
1
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
1
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
|
show 10 more comments
1
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
1
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
1
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
1
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
1
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
1
1
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
I did go to 'Settings->Siri->All' but was only showing one shortcut...
– Bigair
Nov 2 '18 at 1:31
1
1
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
@Bigair see the edited answer.
– Razib Mollick
Nov 2 '18 at 12:00
1
1
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
Is the function makeView(activity: activity) essential? I implemented your code(without the the method above) but still only the last one from allCases shows up on settings app
– Bigair
Nov 6 '18 at 2:31
1
1
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
I exactly copied(except siri activity type string) your code and called from vc on button tap. The setting app still shows only last one of the allCases. Do you mean by exit as to go background or actually wait 10+ till the app's memory is cleaned?(probably not really matters but jus in case)
– Bigair
Nov 7 '18 at 1:05
1
1
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
did you run the code on simulator or on a real device?
– Bigair
Nov 8 '18 at 8:45
|
show 10 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53096110%2fregister-multiple-siri-shortcut-at-once%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I am having the same problem as you, could you solve it?
– Sergio
Nov 22 '18 at 10:22