I am seeking to create a widget for a particular use case. I might like to have the ability to have a consumer faucet on a button (or the widget itself), and place a telephone name. Importantly, the Widget should work whereas the telephone is locked, and never launch the app.
From what I can inform, the one solution to place a telephone name is to open a URL with the next format:
tel://<phone-number>
The issue is I can not open the URL in a Widget. Here is what I’ve tried:
- I’ve handed the URL to the
.widgetURL
methodology like so
struct BeaconWidgetEntryView : View {
let entry: Supplier.Entry
var physique: some View {
VStack {
Textual content(entry.title)
.daring()
Textual content(entry.phoneNumber)
.foregroundStyle(.secondary)
}
.widgetURL(URL(string: "tel://(entry.phoneNumber)")!)
}
}
This simply launches the app, passing on this URL. No good.
- I’ve tried to open the URL in an AppIntent (and carry out the motion on a button faucet), however
UIApplication.shared
shouldn’t be out there in app extensions.
struct CallContactIntent: AppIntent {
static var title: LocalizedStringResource = "Name Contact"
static var authenticationPolicy: IntentAuthenticationPolicy = .alwaysAllowed
static var openAppWhenRun: Bool = false
static var isDiscoverable: Bool = false
@Parameter(title: "Cellphone Quantity")
var phoneNumber: String
init() { }
init(phoneNumber: String) {
self.phoneNumber = phoneNumber
}
func carry out() async throws -> some IntentResult {
guard let callNumber = URL(string: "tel://" + phoneNumber) else { return .consequence() }
await UIApplication.shared.open(callNumber) // Not out there in extensions
return .consequence()
}
}
- I’ve seemed on the
openURL
atmosphere variable in SwiftUI, however I can not cross that into the AppIntent, since it isn’t sendable.
struct BeaconWidgetEntryView : View {
var entry: Supplier.Entry
@Setting(.openURL) personal var openURL // Undecided what I can do with this...
var physique: some View {
VStack {
Textual content(entry.title)
.daring()
Textual content(entry.phoneNumber)
.foregroundStyle(.secondary)
}
}
}
That is intently associated to this query, however not one of the options there work for me.
The explanation I have never but given up on that is Apple’s Widgets are in a position to do that. I created a Shortcut that calls a telephone quantity, and I can name the quantity on faucet whereas the telephone is locked. Is that this one other case of Apple giving their very own apps entry to personal APIs?