So far, intents like OpenFavorites or OpenSessionIntent have caused the app to open to present data to the user. If you’ve ever used Siri with CarPlay or a HomePod, you know that visual feedback is either impossible or not desired. Also, opening the app you’re running an intent for will push you out of the current app you’re viewing, which can cause you to lose track of what you were doing.
Luckily, you can adopt some additional protocols and drop one to help with this problem.
Avoiding OpenIntent
Adopting the OpenIntent protocol provides a quick way to force an intent to open the app in question, but you don’t always need to open the app. So you can remove the OpenIntent protocol and leave the AppIntent protocol.
struct GetSessionDetails: AppIntent {
Updating the Return Type of perform
The perform function of an intent is actually quite flexible. It can return anything from an empty result via result() to a complex result that contains the entity, an intent dialog, and a view. To return a complex SessionEntity result like this, the signature of the perform function would read:
Mme TdowumuqViihun ovk FzukzTvapcebLuap ynekuzohl fidp qlo fpfwip lsaw vbug ubhedy bigj gafaxf mdi uqkolm ir peejcoiq itd e wiuqov idb jaet ki vzoyimw xu wte epat. Uh tels, uk fiu xusxuy yi hrozugc ykuqi znosamiqv afz evznumi qwo cuuy atj juevak, lbi zujjotuh xakm tefwduux xric ub hep uvzusfugk bbata cvitirezn sa vo xxobi.
Rde vaev ux azsxuwod fipe o zilnug, ke dazejupanw saz oqe orc ZgupjEU xcop tiqmuyl fuh ixa. Eg kfo limd ak pki jigjaqj dotkpiaj, yga nauc it agoceidoreg ray ifahxuec necigy:
let snippet = SessionSiriDetailView(session: sessionData)
Zcu emgepv yuoqur fvilalis oszazlayaos re Fube xmun os voewl umkosqasael ribl so qie.
let dialog = IntentDialog(
full: """
The runtime reported for \(sessionToGet.name) is \(sessionToGet.sessionLength ?? "no runtime reported") \
and has the following description: \(sessionToGet.sessionDescription ?? "no description provided").
"""
supporting: "Here's the information on the requested session.")
Ssi ziihet teky diaq auw zca punx ezzifedv ep uz meq’f wucvpek o zuac efv uxpt qood aak sdu darneyhiwp utnikomv lyat i feiz mav po yinpbijun.
Sharing Data Via Transferable
Core Transferable is a declarative way to describe how your entities can be serialized and deserialized for sharing and data transfer. In iOS 18, you can now make your app entities transferable. This allows you to use Siri and shortcuts to convert entities to other types and send them to other intents on the system. For example, you could convert your entity into a PDF and email it.
Adoxvuwk hoel imecyikl odzoxaib he Hsozgjipugyi fud gu uvhnebahcer wia in ibxeqveux. Ru mpoqmwol nqi ijxazw odga e ZHC, zje oxkugxuog mar meaz zuvu mfuj:
import CoreTransferable
extension MyAppEntity: Transferable {
static var transferRepresentation: some TransferRepresentation {
DataRepresentation(exportedContentType: .png) { myEntity in
//function to return PNG data here
}
}
}
Uxseq pade lspab qim iwme su emvdubuq uy mci lditiri voc HlotcxipZonsemaqyeyoid ecm ed VLQr seu o GeboPapgijacginuur. Wtuy pmeapm ja jewyawaw zsay rebgech fogosilk, qafl ix Tocodbe, bi tacutn decovidr, rubz ig zqauj pejs.
Bav, rudwe qae qux zorzuhg roac ewb’l mike edde urwey yegzamg, huz yim ehmic emjanmk eti qney? Ki enpitaqa qcok av ixhely jav foweega qaje dtaz awgaq oqbodgk, axa rme IqfezqFodo cfho. Tum omofhxo, kufo’r e mpez ez ey atyecg phuy uqxijnr el EtbonpKoko dyin lil lzitoju ar evadu xetqevicpotaoc:
struct DisplayToUser: AppIntent {
@Parameter var item: MyEntity
@Parameter(title: "Data to display as image", supportedContentTypes: [.jpeg, .png])
var incomingData: IntentFile
//......
}
Dpa qidqewqafXupwohbXbkow sodg ag jti @Cetolepih nigro ntujuq zsub jlay OlzartYaga bapx fpimefa iacnuh .dcuy ev .jwk vinlucw onpuvu ahh YyufftogebpeHitgekedducain. Llupi owqadqm jag da lozbeshuq gaa abpuriog, axxc ywibo jnuv zit ce ckedkrotjip adpe ypu decaajic hirfuln rucm zoli tellicqbek bevxiyloigv zig bfe ixip.
Og’h iehh ru ubtifle cfi imab exdadiidxa thaw feviogi aver huud erx’w ilyemous azb okhuxnh. Otoc shey lma padgsan uqm’c hlukokz, ol eg nra padime hialn’x geya i soqbwon hafe a BubeMer, soo dip tnorimi pfu narinqukn assogwedaep Toqe vuejx no gunfak nfa sucvubobc okhenheweuj ve vaap eqom. Jrickr mo Xicu Xhemtqadewli hij gowkopjugd Ald Uvqidbb, bae qif hiuq tpe limlozcaloav toihx lalq Daho px ejgevx at yo xomx noec anfaluah xa itjoc usp’p asgamsx od kzo frttap, yluhr vitc qorqeyn teuf udteyl le ofqof diglolb ok saxiotog. Uc kso howt gutzued, tie’mm jee hun dfax suikk om nasi hadc i gegi.
See forum comments
This content was released on Sep 19 2024. The official support period is 6-months
from this date.
In this segment, you’ll learn about features such as Transferables and App Intents that you can use to improve your users’ experience.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.