if #available(iOS 16.0, *) {
print("donated")
let intent = BasicIntent()
IntentDonationManager.shared.donate(intent: intent)
}
Trying to test if donations work with the new App Intents framework.
Donating the shortcut once a user taps a button.
The shortcut is not appearing on the lock screen.
Everything else is working as expected. The Shortcut is appearing in the Shortcuts App and is working via Siri.
In developer settings I have
Display Recent Shortcuts -> On
Display Donations on Lock Screen -> On
Allow Any domain -> On
Allow Unverified sources -> On
Running iOS 16.2, iPhone 11.
Dive into App Intents
RSS for tagDiscuss the WWDC22 Session Dive into App Intents
Posts under wwdc2022-10032 tag
5 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I'm using the AppIntents framework introduced in iOS 16. My goal is to create an AppIntent that performs a long-running task but does open my app when run. When I run the Intent from the Shortcuts app, I see an error message that says the shortcut "was interrupted because it didn't finish executing in time." Is there a way to signal progress to the user of a long-running AppIntent or get more time from the system prior to the AppIntent being cancelled?
My app is mostly implemented in UIKit. Will AppIntents work with UIKit? If so, which (scene or app) delegate method gets called to start the intent?
When you correctly implement EntityPropertyQuery on an AppEntity, Shortcuts will expose a "Find Entity" action that calls into entities(matching:mode:sortedBy:limit:). This is demoed in the "Dive into App Intents" session and works as expected.
However, with this action, you can change the "All Entity" input to a list variable which changes the action text from "Find All Entity" to "Filter Entity where" still giving you the same filter, sort and limit options. This appears to work as expected too. But, what's unexpected is that this filter action does not appear to call any method on my AppEntity code. It doesn't call entities(matching:mode:sortedBy:limit:). One would think there would need to be a filter(entities:matching:mode:sortedBy:limit:) to implement this functionality. But Shortcut just seems to do it all on it's own. I'm mostly wondering, how is this even working?
Here's some example code:
import AppIntents
let books = [
BookEntity(id: 0, title: "A Family Affair"),
BookEntity(id: 1, title: "Atlas of the Heart"),
BookEntity(id: 2, title: "Atomic Habits"),
BookEntity(id: 3, title: "Memphis"),
BookEntity(id: 4, title: "Run Rose Run"),
BookEntity(id: 5, title: "The Maid"),
BookEntity(id: 6, title: "The Match"),
BookEntity(id: 7, title: "Where the Crawdads Sing"),
]
struct BookEntity: AppEntity, Identifiable {
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Book"
var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(title)") }
static var defaultQuery = BookQuery()
var id: Int
@Property(title: "Title")
var title: String
init(id: Int, title: String) {
self.id = id
self.title = title
}
}
struct BookQuery: EntityQuery {
func entities(for identifiers: [Int]) async throws -> [BookEntity] {
return identifiers.map { id in books[id] }
}
}
extension BookQuery: EntityPropertyQuery {
static var properties = QueryProperties {
Property(\BookEntity.$title) {
EqualToComparator { str in { book in book.title == str } }
ContainsComparator { str in { book in book.title.contains(str) } }
}
}
static var sortingOptions = SortingOptions {
SortableBy(\BookEntity.$title)
}
func entities(
matching comparators: [(BookEntity) -> Bool],
mode: ComparatorMode,
sortedBy: [Sort<BookEntity>],
limit: Int?
) async throws -> [BookEntity] {
books.filter { book in comparators.allSatisfy { comparator in comparator(book) } }
}
}
The example Shortcut first invokes entities(matching:mode:sortedBy:limit:) with comparators=[], sortedBy=[], limit=nil to fetch all Book entities. Next the filter step correctly applies the title contains filter but never calls entities(matching:mode:sortedBy:limit:) or even the body of the ContainsComparator. But the output is correctly filtered.
I want to use MapKit with App Intents, but the map does not show up.(See attached image)
Can anyone help me solve this?
import SwiftUI
import MapKit
struct ContentView: View {
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.334_900,
longitude: -122.009_020),
latitudinalMeters: 750,
longitudinalMeters: 750
)
var body: some View {
VStack {
Map(coordinateRegion: $region).frame(width:300, height:300)
.disabled(true)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
import AppIntents
import SwiftUI
import MapKit
struct test20220727bAppIntentsExtension: AppIntent {
static var title: LocalizedStringResource = "test20220727bAppIntentsExtension"
func perform() async throws -> some IntentResult {
return .result(value: "aaa", view: ContentView())
}
}
struct testShortcuts:AppShortcutsProvider{
@available(iOS 16.0, *)
static var appShortcuts: [AppShortcut]{
AppShortcut(
intent: test20220727bAppIntentsExtension(),
phrases: ["test20220727bAppIntentsExtension" ]
)
}
}
Topic:
App & System Services
SubTopic:
Maps & Location
Tags:
App Intents
wwdc2022-10032
wwdc2022-10170