-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppShortcuts.swift
79 lines (69 loc) · 2.61 KB
/
AppShortcuts.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import AppIntents
import UIKit
struct ScanQRCodeIntent: AppIntent {
static let title: LocalizedStringResource = "Scan QR Code"
static let description: LocalizedStringResource = "Scan any QR code within QR Share Pro's scan tab."
/// Launch your app when the system triggers this intent.
static let openAppWhenRun: Bool = true
@MainActor
func perform() async throws -> some IntentResult {
// Create the URL with the `note` parameter as the query parameter
guard let url = URL(string: "qrsharepro://scan") else {
throw URLError(.badURL) // replace `some Error` with URLError
}
// Open the URL
if await UIApplication.shared.open(url) {
return .result()
} else {
throw URLError(.unsupportedURL)
}
}
}
struct CreateQRCodeIntent: AppIntent {
static let title: LocalizedStringResource = "Create QR Code"
static let description: LocalizedStringResource = "Generate a QR code with the desired text."
/// Launch your app when the system triggers this intent.
static let openAppWhenRun: Bool = true
@Parameter(title: "QR Code Text or URL")
var note: String
@MainActor
func perform() async throws -> some IntentResult {
// Create the URL with the `note` parameter as the query parameter
guard let url = URL(string: "qrsharepro://new?q=\(note.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "")") else {
throw URLError(.badURL) // replace `some Error` with URLError
}
// Open the URL
if await UIApplication.shared.open(url) {
return .result()
} else {
throw URLError(.unsupportedURL)
}
}
}
struct QRShareProShortcutsProvider: AppShortcutsProvider {
@AppShortcutsBuilder
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: CreateQRCodeIntent(),
phrases: [
"Create QR Code with \(.applicationName)",
"Generate QR Code with \(.applicationName)",
"Create",
"QR Code",
],
shortTitle: "Create QR Code",
systemImageName: "qrcode"
)
AppShortcut(
intent: ScanQRCodeIntent(),
phrases: [
"Scan a QR Code with \(.applicationName)",
"Scan QR Code with \(.applicationName)",
"Scan a QR Code",
"Open QR Code Scanner"
],
shortTitle: "Scan QR Code",
systemImageName: "qrcode.viewfinder"
)
}
}