Post not yet marked as solved
Hi,
I'm new to Swift development and encountering an issue that I believe may be due to an error on my part.
I have two questions regarding the following code:
import AppIntents
import SwiftUI
import SwiftData
@available(iOS 17.0, *)
struct CopiarEventoIntent: AppIntent {
@Environment(\.modelContext) private var context
@Parameter(title: "Nome do Evento")
var name: String
@Parameter(title: "Data Inicial")
var datai: Date
@Parameter(title: "Data Final")
var dataf: Date
@Parameter(title: "Tipo de Evento")
var tipo: String
@Parameter(title: "Endereço")
var endereco: String
@Parameter(title: "Lembrete")
var reminder: Bool
static var title: LocalizedStringResource = "Adicionar Eventos"
static var description = IntentDescription("Copiar Eventos e alterar datas", resultValueName: "Resultado")
@MainActor
func perform() async throws -> some IntentResult & ProvidesDialog {
let calData = CalData(title: name, datei: datai, datef: dataf, tipo: tipo, endereco: endereco,reminder: reminder)
context.insert(calData)
return .result(dialog: "Evento copiado com sucesso!")
}
}
@available(iOS 15.0, *)
struct AppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: CopiarEventoIntent(),
phrases: [
"Copiar Evento"
],
shortTitle: "Copiar Evento",
systemImageName: "square.and.arrow.down"
)
}
}
@available(iOS 15.0, *)
struct ShortcutSelectionView: View {
@Environment(\.modelContext) private var context
@Query(sort: \CalData.title) private var caldatas: [CalData]
@State private var selectedEvent: CalData?
var body: some View {
List(caldatas, id: \.self) { eventData in
Button(action: {
selectedEvent = eventData
handleEventSelection()
}) {
Text(eventData.title)
}
}
}
private func handleEventSelection() {
guard selectedEvent != nil else { return }
}
}
When I run the shortcut, gives me the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot insert 'CalData' in this managed object context because it is not found in the associated managed object model.
I attempted to save this using SwiftData with the following model:
import SwiftData
@Model
class CalData {
var title : String
var datei : Date
var datef : Date
var tipo : String
var endereco : String
@Relationship(deleteRule: .cascade) var caldataval = [CalDataVal]()
var reminder: Bool = false
init(title:String, datei:Date, datef:Date, tipo:String, endereco:String, reminder:Bool){
self.title = title
self.datei = datei
self.datef = datef
self.tipo = tipo
self.endereco = endereco
self.reminder = reminder
}
}
As for the second question, how can I add a parameter that can have multiple values to save them to EventDataVal, resembling a one-to-many relationship:
import SwiftData
@Model
class CalDataVal {
var name : String
var value : Double
init(name:String, value:Double){
self.name = name
self.value = value
}
}
Thanks in advanced
Post not yet marked as solved
Hello IOS Dev Community, I'm very new to Apple shortcuts and am on a journey to build up a series of shortcuts to make my life easier on Mac. I have Google Drive linked to Finder, then I made a program like the one below which allows me to select a destination folder in the said Drive folder and move the most recent downloaded file over. I usually start the program by typing in the spotlight search bar, but it would show this error: "ls: .: Operation not permitted"
but, when I actually open the Shortcuts app and click run, it works perfectly fine, what could be the reason behind this?
Thank you guys
Post not yet marked as solved
Hello iOS Developer Community,
I hope this message finds you healthy and happy. I am reaching out to seek your expertise and assistance with a particular challenge I’ve encountered while using the Speak Screen and Speak Selection features on iOS.
As you may know, these features are incredibly useful for reading text aloud, but they sometimes struggle with the correct pronunciation of homographs—words that are spelled the same but have different meanings and pronunciations. An example of this is the word “live,” which can be pronounced differently based on the context of the sentence.
To enhance my user experience, I am looking to input corrections for the pronunciation of “live” in its “happening now” context, such as in “live broadcast” or “live event.” However, the current process requires manual entry for each phrase, which is quite labor-intensive.
I am wondering if there is a way to automate or streamline this process, perhaps through a shortcut or script that allows for bulk input of these corrections. Additionally, if anyone has already compiled a list of common phrases with homographs and their correct pronunciations, I would greatly appreciate it if you could share it or guide me on where to find such resources.
Your insights and guidance on this matter would be invaluable, and I believe any solutions could benefit not just myself but many other users facing similar issues.
Thank you for your time and consideration. I look forward to any suggestions or advice you may have.
Best regards,
Alec
Post not yet marked as solved
I am exploring Appi-Intent and Appshortcut. We can create an action shortcut by using the following code.
struct WatchListShortcut: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: WatchListAppIntent(),
phrases: [
"Tell \(.applicationName) to open first item in watch list",
],
shortTitle: "WatchList item",
systemImageName: "systemimage"
)
}
}
What I want to show an entity shortcut like shown in the below screenshot.
linkText
I am not sure how to create the shortcut like Assigned one in the above screen.
Post not yet marked as solved
hi there,
would someone kindly show me the syntax for the following please.
I have the shortcut scan which is good but i want to save the scan to
Icloud / documents / and then to a folder called scans.
i somehow have the syntax wrong when in the "save" area I have Save file to Icloud drive then Subpath to the folder "scans" but this doesn't seem to work.
Anyone put me in the correct direction please ?
regards
Nick
Post not yet marked as solved
Currently I am trying to create some shortcuts for my iOS 17 app. The AppIntent looks like this:
class PostClass{
public init() {
let url = URL(string: "http://myurl")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
struct Message: Encodable {
let device_type: String
}
let message = Message(
device_type: "device"
)
let data = try! JSONEncoder().encode(message)
request.httpBody = data
request.setValue(
"application/json",
forHTTPHeaderField: "Content-Type"
)
self.request = request
}
}
var activateDevice = PostClass()
@available(iOS 17, *)
struct ActivateIntent: AppIntent {
static let title: LocalizedStringResource = "Activate"
func perform() async throws -> some IntentResult {
let task = URLSession.shared.dataTask(with: activateDevice.request) { data, response, error in
let statusCode = (response as! HTTPURLResponse).statusCode
if statusCode == 200 {
print("SUCCESS")
} else {
print("FAILURE")
}
}
task.resume()
return .result()
}
}
Unfortunately, the shortcut throws an error after every second execution. I looked into the ips-file and saw the following traceback:
Thread 2 Crashed:
0 Runner 0x1028ddd30 closure #1 in ActivateIntent.perform() + 388
1 CFNetwork 0x1a6f39248 0x1a6f2a000 + 62024
2 CFNetwork 0x1a6f57210 0x1a6f2a000 + 184848
3 libdispatch.dylib 0x1adced13c _dispatch_call_block_and_release + 32
4 libdispatch.dylib 0x1adceedd4 _dispatch_client_callout + 20
5 libdispatch.dylib 0x1adcf6400 _dispatch_lane_serial_drain + 748
6 libdispatch.dylib 0x1adcf6f64 _dispatch_lane_invoke + 432
7 libdispatch.dylib 0x1add01cb4 _dispatch_root_queue_drain_deferred_wlh + 288
8 libdispatch.dylib 0x1add01528 _dispatch_workloop_worker_thread + 404
9 libsystem_pthread.dylib 0x201dd4f20 _pthread_wqthread + 288
10 libsystem_pthread.dylib 0x201dd4fc0 start_wqthread + 8
Is there any way to locate the error with these information? Has it something to do with the fact that my code is not thread-safe? Or is there any internal bug?
Grateful for any help, thanks in advance!
I'm currently exploring how to implement the AppIntent parameter with a list of apps similar to what's shown in the screenshots provided below:
I'm particularly interested in how the searchable list of apps is implemented. My current approach involves creating an enum for the apps, but it lacks searchability and requires manual addition of each app.
Does anyone have an idea on how this functionality might be implemented? It appears that the searchable list might be a native Apple view, but I haven't been able to find any documentation or resources on it. Any insights or pointers would be greatly appreciated!
Post not yet marked as solved
Creating AppEntity objects for use as AppIntents to do filtering no longer works in iOS 17.4. If you have a prior shortcut setup that does that, then it will work. It seems some apps still work, but mostly i see the app shortcut action no longer has the Filtering options.
Post not yet marked as solved
On macOS Sonoma (not tested with other systems) there is a bug when you have the home folder on a separate volume and you use the shortcuts apps to generate standalone programs that you can add to the dock.
I found out why : those shortcuts are generated inside the Application folder that is in the home directory but when the whole home directory is not on the same volume as the system itself then you're greeted with a permission issue message.
The workaround is to make a symbolic link between "external volume/home/Applications" and "main volume/home/Applications" to trick the shortcuts app into generating those standalone apps.
Would be great to have this fixed.
Post not yet marked as solved
I would like to request the ability to group windows in mission control so that I can easily swap all windows between my 2 external monitors easily. Anyway to make swapping all windows between the displays easier would be a huge time saver.
Making this an option in shortcuts would work as well.
Post not yet marked as solved
I am working on an application design where I would like to have the Iphone running an app such as Apple Map, and while I might be driving in the car I would like to have my apple Watch invoke a screen shot of the current view of I map showing my location without having to use the iphone.
So the Iphone would be active and in a car holder displaying my location on the map.
Once I made my route point, such as a waypoint. I would like to press a button on my watch app to do a screen print.
Second though is, could I press a button on my Apple Watch app to fire an request to my own IOS Application using WatchConnectivity to capture my Location to a data file.
Third thought is could a press a button on my Apple Watch app to interact with an active app, which is an app like a reminder app and create a new Reminder Note in the active app in focus on my Iphone, but is not a component of my IPhone App.
Thanks for any insight how I could make a Apple Watch app send Button Presses reliably to my Iphone Application active, so that I. could avoid having to touch my iPhone?
Thanks in advance for any guidance.
Post not yet marked as solved
My requirement is to execute this shortcut on the Apple Watch, where I input speech, and it's converted into text to be saved in the memo app. However, the shortcut doesn't function correctly on the Apple Watch, and I can't sync the content to the memo app. Suspecting an issue with synchronization, I added the current time along with my voice input, only to find that while the current time gets transferred, the text does not.
I wondered if the problem was with voice input, so I tried switching to keyboard input, but the outcome remained unchanged.
I have tested this issue on multiple Apple Watches and found the problem persists across all devices. Both my phone and iWatch are updated to the latest system versions.
https://www.icloud.com/shortcuts/d58d14627dbe450ead5e9217e1a68c27
Hi,
Anyone can tell me where is stored the customized shortcut for dictation on macOS Sonoma?
By mistake I customize one shortcut (it stores always the last one) and I want to restore the default shortcut dropdown list.
From the image I want to delete "Command+F" and restore the dropdown list.
Thank you.
Regards
FA
Post not yet marked as solved
I have several AppEnum in my app and I can no longer succesfully get a value using requestValue / requestDisambiguation methods in when running an AppIntent.
They all stopped working in iOS 17.4; The list of cases does show to the user but uppon selection it throws the following error:
AppIntents.PerformIntentError.unsupportedValueType
Post not yet marked as solved
The app's password conditions are not functioning properly. Upon entering the wrong password, the app still allows access. Additionally, when prompted for input upon opening the app, clicking the cancel button allows access without requiring the [password.
Post not yet marked as solved
Hi,
I would like to make a shortcut enter a keyboard short, CMD+m to be precise. Note that I dont want to run the shortcut when pressing CMD+m. The shortcut should press CMD+m, if that makes sense. Is javascript an option? How would the code look like?
Post not yet marked as solved
I have a problem with shortcuts. I try to build a shortcut for recognizing some words and numbers in JPEG files. I noticed that if I select all the text in Preview app some words can be found that Shortcuts text extraction command cannot return.
do you know if his is normal?
Is it possible to use preview extraction in shortcuts ?
Thanks
Post not yet marked as solved
hello I'm almost finished creating the app but I'm just missing one feature. This is that when the user installs the installation when he opens application A it immediately redirects him to application B which will be mine on a specific page. Can you tell me how I can do this?
There is an application that does exactly the same thing, it's 'one sec' my application is identical
Post not yet marked as solved
My app has an AppIntent that returns a collection of AppEntity items.
Using a shortcut with the repeat with each action to loop the entities, it prompts me multiple times to allow to share the entities (I select "Always Allow" on the first one, but it keeps asking over and over).
All the prompts after the first one, shows an incorrect note saying something like:
"Previously this shortcut was allowed to share 1 item with …"
the count of items shared is always wrong, for example,
if I initially selected "Always Allow" for 10 entities on the first prompt,
the second says previously 1 item,
the third prompt actually has the count right, saying 10 items,
and then a fourth prompt (seems to be the last one) says something like 40 items
Some more facts:
This issue does not happen for example when I fetch entities from a system based intent, like get calendar events. It correctly only prompt for my permission once
My app is already on the app store
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.