Post not yet marked as solved
So I'm working on a logging app that uses Siri to log diaper changes for babies. There are 3 types of diaper changes, wet, dirty, both.
I created a enum for these values in the intent definition file and made it configurable and resolvable.
in the resolve function, I added this line of code
public func resolveDiaperType(for intent: DiaperIntentIntent, with completion: @escaping (DiaperTypeResolutionResult) -> Void) {
let needsValue = intent.diaperType == .unknown
if needsValue {
completion(.needsValue())
} else {
completion(.success(with: intent.diaperType))
}
}
But as soon as .needsValue() is called, the UI will ask user to select one value, and then crash the app.
I tried removing a lot of different params and code blocks, needsValue is the only thing that's crashing for me. If I make the default diaperType parameter as .dirty instead of .unknown, it works.
Basically it won't let me work with an empty enum parameter.
I get the SIGABRT error and the app crashes.
I have like 4 intents. 3 of them uses enums. All 3 crash on the enum input UI. all 3 work correctly when the enum is given a value instead of .unknown.
The problem is, I NEED to ask user the type.
If I give it a default value and resolve it with .needsValue(), it still crashes.
I cannot ask the user for a value.
I haver made siri intents with enums input before. And those intents STILL WORK.
They were just made for older Xcode versions
Is this an Xcode bug?
Testing on iOS 17.2 simulator
Xcode 15.2
Post not yet marked as solved
I have an Intents definition file for a Custom Intent that I want to convert to an AppIntent.
The Custom Intent has the checkbox "Configurable in Shortcuts" not checked and therefore the "Convert to App Intent" Button is greyed out. I can however still do a conversion using the Menu-Item "Editor"->"Convert to App Intent". The intent has a number of parameters that are not configurable, but were set in code. This way it was possible to donate shortcuts with the parameters (and even the title) set in code. The automatic conversion using the menu item however produces a result that does not match the legacy Custom Intent (Parameters appear in the Shortcuts App etc). I also did not find any way to create AppIntents that have parameters that can be set in code, before the intent is donated.
I would leave the old legacy Custom Intents as they are, but as soon as make use of any of the new iOS 16 Shortcut features (App Shortcuts) the existing donated Custom Intents disappear in the Shortcuts App. Given the apparent inability to convert them into AppIntents due to the missing code-set parameters, I would be happy for any advice on potential solutions.
Post not yet marked as solved
I have added an "App Intents Extension" target to my main application in macOS. This generated the below two files:
TWAppIntent.swift
import AppIntents
struct TWAppIntent: AppIntent {
static var title: LocalizedStringResource = "TWAppIntent"
static var parameterSummary: some ParameterSummary {
Summary("Get information on \(\.$TWType)")
}
// we can have multiple parameter of diff types
@Parameter(title: "TWType")
var TWType: String
func perform() async throws -> some IntentResult {
return .result(dialog: "Executed TWAppIntent.")
}
}
TWAppIntentExtension.swift
import AppIntents
@main
struct TWAppIntentExtension: AppIntentsExtension {
}
I m able to build the extension target and I my intent action is available in the shortcuts app. However, on launching a shortcut with the above created intent action. I m getting the below popups:
From what I understand, I m getting this error because I have not added my 'TWAppIntent' to the TWAppIntentExtension.swift file which is the entry point for the extension, but I could not find any documentation around how to add it. Can someone help on how to do it or Is there something else that I m doing wrong?
Post not yet marked as solved
Hello.
My project includes a widget target that provides interactive widget functionalities. The document "Adding Interactivity to Widgets and Live Activities" says the following:
Additionally, note that the perform() function is marked as throws. Be sure to handle errors instead of rethrowing them, and update your app, widget, and Live Activity as needed. For example, update a widget’s interface to indicate that it displays outdated information if it cannot load new data.
https://developer.apple.com/documentation/widgetkit/adding-interactivity-to-widgets-and-live-activities#Implement-the-perform-function, column 3
However, I couldn't find a way how to handle an error in an interactive widget. The Button(intent:) and Toggle(intent:) initializers don't have mechanisms for error handling.
Does anyone know a solution for handling errors in interactive widgets?
Post not yet marked as solved
my app intent is to read the pasteboard and save data to app with swiftData.
it worked very well on Simulator, but didn't work on my device
Post not yet marked as solved
Adding the AppIntent of my app as AppShortcuts to the Shortcuts Apps was easy. This only required an AppShortcutsProvider. However, I am confused how the AppShortcuts are shown in the Shortcuts App. It seems that there are different styles enter image
The AppShortcuts of some apps are shown as tiles
While shortcuts from other apps are shown as collection of circle icons
Some "circle collection" use a default gray background with blue icons
Others color or even gradient backgrounds with white icons
The only thing I found that might be related to the design is the shortcutTileColor property in the AppShortcutsProvider. However using/changing this property has no effect on how my app's shortcus are shown: On the default gray background / blue icon.
Among the different apps on my devices I cannot see any logic which shortcuts are shown as tiles and which as circle icons. Additionally third party apps use colored background or gradients. So there there has to be a way to change this. But how?
Post not yet marked as solved
AppIntens can be used as actions when working with Shortcut Automation. iOS offers a bunch of different triggers to start an automation, such as "Time of Day", "Email", "Transaction", etc.
Depending on the trigger one can then pass different "Shortcut input" values as parameters to the App Intent. While in many cases the expected type is quite obvious, this is not always the case.
An Email type input for example offers Subject, Sender, Recipients, Attachments, Content, Name.
Subject will be most likely a String.
But is Sender also a String or maybe an IntentPerson?
Is Recipients a String (e.g. comma separated) or a collection?
Is Attachments a [String], [URL] or [IntentFile]?
How to I find out of which types these inputs have? Is there a better way than guessing and trial and error? The documentation provides very little information about supported types in general and I could find nothing about the types used by different triggers.
Additionally each "Shortcut input" offers it self as parameter. So the Email type input does not only offer Subject, Sender, etc. as input parameters but also Email. What parameter type does an intent need no accept in order to receive on Email object?
Thank you very much for your help.
Post not yet marked as solved
The Shortcuts app offers the possibility to trigger shortcuts/intends when a wallet credit card is used and a new transaction is created.
I would like to add transaction details to one of my apps and use such a shortcut for it. Other apps do the exact same thing, so this should not be a problem.
Adding a shortcut to my app was not a big deal. However, how can this be tested on simulator?
When trying to add a new automatization in the Shortcuts app using a wallet transaction as trigger I cannot finish the setup dialog since the Next button is disabled. I assume this is because no card is configured.
When trying to add a card in Wallet I just receive that this was not successful.
I have connected the simulator to a Sandbox Apple ID account using a region which supports Apple Pay (US). Using a real account does not solve the problem.
Any idea how to get this working?
Using real transaction within a store could obviously not be the solution for debugging.
In my app, there's a widget that should change to one color when clicked and then to another color after 10 seconds.
When I click the widget button (linked to the App Intent), the widget should refresh. When I debug, this happens as expected.
However, if I call WidgetCenter.shared.reloadAllTimelines() in the perform() method of AppIntent, the widget timeline doesn't refresh right away. This issue only happens on real devices and isn't always consistent. In the simulator, the widget refreshes as expected.
Post not yet marked as solved
I show some content in LiveActivity Dynamic Island and added a button. As buttons work with App Intent I created an Intent. When the button is clicked I get the following error
Could not find an intent with identifier MyIntent, mangledTypeName: Optional("19LiveWidgetExtension10MyIntentV")
MyIntent.swift
import Foundation
import AppIntents
struct MyIntent: LiveActivityIntent {
public init() { }
func perform() async throws -> some IntentResult {
print("click")
return .result()
}
}
MyLiveActivity.swift
...
DynamicIslandExpandedRegion(.bottom) {
HStack(alignment: .top) {
Button(intent: MyIntent()) {
Image(systemName: "bolt.fill")
}
}
.tint(.white)
.padding()
}
....
The Intent is added to all targets. Any ideas?
Post not yet marked as solved
Hello guys
Im searching a way to create, or to use an existent shortcut to limit timetables for certain applications.
My goal is not to limit the daily maximum time for using an application.
An example: my Iphone would not permit me to use tiktok from 6.00 AM to 8.00 AM
Thank you in advance
Post not yet marked as solved
Recently I realized that even though I was able to add my app's intents in the Shortcuts app, selecting any of the parameters didn't show the popup list of suggestions (the ones declared by DynamicOptionsProvider in the AppIntent subclass) and running it showed an error.
In the image you can see the two suggestions for the working app version ("asdf" and "bla") that would not be there in the non-working version.
I knew that when I had added this functionality, it worked, so I found the app version that caused the App Intents Extension to stop working. Apparently, the problem was that I had removed the Swift files declared in the app extension from my main app's target. Probably when I first added the App Intents Extension I had noticed that adding the extension's source files to the main target made it work, but later thought that it shouldn't be necessary and didn't test if it still worked.
Today I created an empty project with a new App Intents Extension and confirmed that the Shortcuts app was correctly showing the parameter popup suggestions, even without including the extension's source files in the main target. Then during the course of almost an entire day I gradually reduced my original Xcode project to this new sample project to find what else would make the extension work, other than including the extension's source files in the main target.
My very last resource was changing the bundle identifier, which solved the issue. My original project's targets have identifiers like org.domain.OriginalApp and org.domain.OriginalApp.AppIntent, while the sample project's targets have identifiers like org.domain.SampleApp and org.domain.SampleApp.AppIntent.
How could including the App Intents Extension's source files in the main target or changing the bundle identifiers cause the Shortcuts app to correctly show the parameter popup suggestions?
Post not yet marked as solved
Is it possible to get the original date created for an IntentFile? The following code always gets the date for right now, surely because it's copied into a temporary directory so that's when it was created at that location.
if let fileURL = file.fileURL, fileURL.startAccessingSecurityScopedResource() {
if let attributes = try? FileManager.default.attributesOfItem(atPath: fileURL.path), let date = attributes[.creationDate] as? Date {
print(date)
}
fileURL.stopAccessingSecurityScopedResource()
}
Post not yet marked as solved
Sorry if I'm in the wrong category for this :pray:
Please see this MRE for clarity:
https://github.com/MartinP7r/IntentTest
(I used the example code from https://developer.apple.com/wwdc22/10032 except for deprecation warnings)
The compiler throws an error Unable to determine value type for type IntentPackage.Shelf.
According to comments in this question it's because the type I'm extending to AppEnum is not in the app target's module, but in a Swift Package.
And yes, copying Shelf into the target will solve the issue, but I really don't like having to duplicate the types just to make it work and was wondering if there's any way to just use the type from the Swift package and only add the AppEnum conformance in the main target.
Post not yet marked as solved
Hello everyone,
I want to add preconfigured app shortcuts for my app using an AppShortcutsProvider implementation. I have been following this demo from WWDC22: https://developer.apple.com/wwdc22/10170
All looks pretty straight forward.
However, I would like the preconfigured shortcuts to be based on the state of the data in the app: adding one shortcut for every user-entered item in a list.
Now, this might be due to the fact that I'm a Swift novice, but I can't figure out how to do that from a AppShortcutsBuilder property as I can't create the AppShortcut instances in a for loop. I have failed to find any resources online on this. I assume I would need the ForEach equivalent of the ViewBuilder? Is anything like that available for AppShortcutsBuilder?
I have also stumbled on this: https://developer.apple.com/documentation/sirikit/offering_actions_in_the_shortcuts_app
But this solution seems to only work with INIntents rather than AppIntents. Is there a setShortcutSuggestions equivalent for AppIntents that I could call when the contents of my list change?
Post not yet marked as solved
If a user sets up a Shortcut to execute when the Settings app is opened, it will only trigger if the Settings app is opened from the home screen.
If, though, the user opens settings through the Control Center (e.g. by holding down on Wi-Fi and tapping "Wi-Fi Settings..."), it will open the Settings app but not trigger the Shortcut.
Is there any way to fix this?
Post not yet marked as solved
How to disable iOS Shortcut ( Automation ) Programmatically ?
I have made an automation to open my app whenever a user opens Facebook app. When the user taps on "Continue with Facebook" the automation which is forcing to open my App show be disabled for 2 minutes. How can I achieve this?
Post not yet marked as solved
Hello Community,
I recently started to work on shortcuts with AppIntent and I want to have an image output on my shortcut action.
The output of a string is simple and working:
func perform() async throws -> some IntentResult & ReturnsValue<String> {
let myString : String = "Hello World"
return .result(value: myString)
I am having trouble to return an image. Ideally I want to load an image from iCloud Drive or from a website and throw image result.
I tried
func perform() async throws -> some IntentResult & ReturnsValue<Image> {
and
func perform() async throws -> some IntentResult & ReturnsValue<INFile> {
, but was not apple to write a proper code to
return .result(value: myImage)
.
Any help is very welcome and highly appreciated.
Have a good week
Eric
Post not yet marked as solved
@MainActor
perform() async throws -> some IntentResult {
// ...
switch locationManager.authorizationStatus {
case .denied, .restricted:
throw UserLocationError.permissionDenied
case .notDetermined:
await locationManager.requestWhenInUseAuthorization() // to ask permission
default:
break
}
// ...
}
Here is my code.
When the authorizationStatus is .notDetermined,
it invokes requestWhenInUseAuthorization() method on the main thread,
but throws UserLocationError.permissionDenied immediately, eventhough I didn't deny the permission.
It's really weird and unexpected that it throws UserLocationError.permissionDenied when the status is not .denied or .restricted
Even it invokes requestWhenInUseAuthorization(), there's no alert for asking permission
If there's any solution, please let me know
Post not yet marked as solved
We have an app that uses Siri Shortcuts in iOS 16. WWDC '23 announced more flexible shortcut phrase matching in iOS 17 when apps are built with Xcode 15 run on Sonoma. I've downloaded and installed (Xcode and Sonoma) and rebuilt the app. I've ensured that "APP_SHORTCUTS_ENABLE_FLEXIBLE_MATCHING = YES" in the Build Settings. Unfortunately the App Shortcuts Preview Window shows the following error when I click on my build "No Flexible Matching Assets - This target is for a platform which is not supported by Flexible Matching or does not have Flexible Matching enabled"
Other things I tried: I set our minimum deployment target to iOS 17 and built for an iOS 17 Simulator.
Any ideas on how to get flexible matching for shortcut phrases?