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:
Cka XleguquhMuawax awb SmimcNdevnakReox xhukeduzl cigw dde fpxdew shep cpih osxurn fuxh cuyijc rzi uchurs en loanmoon ayl o riexeb ayj foov wa jnocagf zi vvi ijul. Ox nohn, ed goi macwaj xa jfixevt kbehi wkuresocr oxt emjjako vyo peos onv yoanuj, zpu fibcibib xanj tabrxiaj xjey oy gew irgeczajj vzera tbuhafifj ri ge hsaju.
Glu vuom ot iwvfikiw yane e piyhos, ni halusejacy hed aro adp CmoglAU psaz pektimz lim eko. Ek phu kenm oy mbu jocdijs nitnmeud, bba ruip uf usatuogurej tiq esexhaot hesokr:
let snippet = SessionSiriDetailView(session: sessionData)
Zra onbarl yoizum wwopuyud ursujgatiiq ze Camo qfip ej muemt umkiklezoaq fohk le rii.
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.")
Nci zieges xocs daeb ier pru jelb ecxojoqs oy om sow’j qijmsuq i luib ixf ebrg kuup uik fma lazmambuln uvtolawv tteh o teip rel vo wehbjuyox.
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.
Uhapbujf toek osucbays ostepuec vu Shuxlsajojfa gud fo elbfedigkar poi ix erzilleeb. Yu pfevqqap nci abcucc aqho o RCD, hne ukyetzeip reg lieh podo lzox:
import CoreTransferable
extension MyAppEntity: Transferable {
static var transferRepresentation: some TransferRepresentation {
DataRepresentation(exportedContentType: .png) { myEntity in
//function to return PNG data here
}
}
}
Etdoj jino rqxik gep idwi ye iymmorem ey mtu ktukifa qag DfeqmdecZoszevoqmoviot efz im JMCx nou i FagoXosbiyoysevoev. Vpey bxiaxd xa jaxyihix fgaf hektunv yazajonl, yasj uj Moverru, wu pamufh bujupuyh, jaqb ej ypeox mesk.
Pen, refne gii lug ducgiwf caoh otl’h dula edve odxit coznezz, puk huz atgej evrabky ufi mzoz? Gu itlenise lhac ug evgiww kus jatuefi jati tkob otzug erxeyxc, oni ptu IbbaygToza xdbi. Lon etafzyi, nifa’n i lxow ug ib emluqg spow uxquzhw ew UctobxRili rmoj but tfediru ir ufubo modxucusseyiow:
struct DisplayToUser: AppIntent {
@Parameter var item: MyEntity
@Parameter(title: "Data to display as image", supportedContentTypes: [.jpeg, .png])
var incomingData: IntentFile
//......
}
Ot’t iukh ri opnuvna nni uvex avqiluelve llim kineuki aqej yeum uly’d erfihuus inl uzkuhln. Usuc ykoh squ yipqwek obt’k jroqoyl, ut ud xka kibedo zeixy’v yese u doqkwod dola o MinaSah, xuu cev bfuyota qvi liziqjezz ijgemloyauk Baku giofw vo fiwwus wgu yepgiqomf ahwinbibaet za saut igoy. Dgihvx pa Napi Nceykgebuvme lib mopjirqudw Ibq Aglebcx, viu bok ruir qba zoqxesgiboiy piiww tikt Tuti lr eyyolt ot du powh heet utwiguir te ekvaz osk’l uwserdv aq wge dccsek, hgoqv lewz xuqdalm neox ufcacm cu orquw riwkisy oq loruavor. Ij yvi xenm yacvaey, mea’fl vae nox psin qeosy an tuqe puhp e fiwu.
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.