I have already got an iOS 17 App Intent that works with a URL:
@accessible(iOS 16, *)
struct MyAppIntent: AppIntent {
static let title : LocalizedStringResource = "My App Inent"
static let openAppWhenRun : Bool = true
@MainActor
func carry out() async throws -> some IntentResult{
await UIApplication.shared.open(URL(string: "myapp://myappintent")!)
return .end result()
}
}
Now, with iOS 18 and Management Widgets, I wish to create a Management Widget button that merely opens the app with the identical URL. Nevertheless, UIApplication
code is just not allowed inside extensions. For this, Apple says to make use of OpenIntent
which is proven right here:
Apple Pattern Code from the hyperlink:
import AppIntents
struct LaunchAppIntent: OpenIntent {
static var title: LocalizedStringResource = "Launch App"
@Parameter(title: "Goal")
var goal: LaunchAppEnum
}
enum LaunchAppEnum: String, AppEnum {
case timer
case historical past
static var typeDisplayRepresentation = TypeDisplayRepresentation("Productiveness Timer's app screens")
static var caseDisplayRepresentations = [
LaunchAppEnum.timer : DisplayRepresentation("Timer"),
LaunchAppEnum.history : DisplayRepresentation("History")
]
}
WWDC session video about this doesn’t cowl this specific methodology intimately and likewise this pattern code is a bit complicated.
So how can I alter this code to simply open the app with a URL?