Skip to content

Commit a34fade

Browse files
authored
chore(ios): consolidate optional argument standard (tauri-apps#1738)
* chore(ios): consolidate optional argument standard mark all optional iOS arguments as `var <name>: Type?`, following the pattern described in the documentation: https://v2.tauri.app/develop/plugins/develop-mobile/#ios * chore: add missing Info.plist to example
1 parent 713c54e commit a34fade

File tree

9 files changed

+68
-60
lines changed

9 files changed

+68
-60
lines changed

examples/api/src-tauri/Info.plist

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict>
5-
<key>NSCameraUsageDescription</key>
6-
<string>Request camera access for WebRTC</string>
7-
<key>NSMicrophoneUsageDescription</key>
8-
<string>Request microphone access for WebRTC</string>
9-
</dict>
4+
<dict>
5+
<key>NSCameraUsageDescription</key>
6+
<string>Request camera access for WebRTC</string>
7+
<key>NSMicrophoneUsageDescription</key>
8+
<string>Request microphone access for WebRTC</string>
9+
<key>NSFaceIDUsageDescription</key>
10+
<string>Authenticate with biometrics</string>
11+
</dict>
1012
</plist>

examples/api/src-tauri/gen/apple/api_iOS/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
<string>UIInterfaceOrientationLandscapeLeft</string>
4141
<string>UIInterfaceOrientationLandscapeRight</string>
4242
</array>
43+
<key>NSFaceIDUsageDescription</key>
44+
<string>Authenticate with biometrics</string>
4345
<key>NSCameraUsageDescription</key>
4446
<string>Request camera access for WebRTC</string>
4547
<key>NSMicrophoneUsageDescription</key>

plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import WebKit
99

1010
struct ScanOptions: Decodable {
1111
var formats: [SupportedFormat]?
12-
let windowed: Bool?
13-
let cameraDirection: String?
12+
var windowed: Bool?
13+
var cameraDirection: String?
1414
}
1515

1616
enum SupportedFormat: String, CaseIterable, Decodable {

plugins/biometric/ios/Sources/BiometricPlugin.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class BiometricStatus {
2525
struct AuthOptions: Decodable {
2626
let reason: String
2727
var allowDeviceCredential: Bool?
28-
let fallbackTitle: String?
29-
let cancelTitle: String?
28+
var fallbackTitle: String?
29+
var cancelTitle: String?
3030
}
3131

3232
class BiometricPlugin: Plugin {

plugins/geolocation/ios/Sources/GeolocationPlugin.swift

+23-19
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5+
import CoreLocation
56
import SwiftRs
67
import Tauri
78
import UIKit
89
import WebKit
9-
import CoreLocation
1010

1111
class GetPositionArgs: Decodable {
12-
let enableHighAccuracy: Bool?
12+
var enableHighAccuracy: Bool?
1313
}
1414

1515
class WatchPositionArgs: Decodable {
@@ -101,14 +101,14 @@ class GeolocationPlugin: Plugin, CLLocationManagerDelegate {
101101
if CLLocationManager.locationServicesEnabled() {
102102
// TODO: Use the authorizationStatus instance property with locationManagerDidChangeAuthorization(_:) instead.
103103
switch CLLocationManager.authorizationStatus() {
104-
case .notDetermined:
105-
status = "prompt"
106-
case .restricted, .denied:
107-
status = "denied"
108-
case .authorizedAlways, .authorizedWhenInUse:
109-
status = "granted"
110-
@unknown default:
111-
status = "prompt"
104+
case .notDetermined:
105+
status = "prompt"
106+
case .restricted, .denied:
107+
status = "denied"
108+
case .authorizedAlways, .authorizedWhenInUse:
109+
status = "granted"
110+
@unknown default:
111+
status = "prompt"
112112
}
113113
} else {
114114
invoke.reject("Location services are not enabled.")
@@ -161,16 +161,18 @@ class GeolocationPlugin: Plugin, CLLocationManagerDelegate {
161161
}
162162
}
163163

164-
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
164+
public func locationManager(
165+
_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]
166+
) {
165167
// Respond to all getCurrentPosition() calls.
166168
for request in self.positionRequests {
167-
// The capacitor plugin uses locations.first but .last should be the most current one
168-
// and i don't see a reason to use old locations
169-
if let location = locations.last {
170-
let result = convertLocation(location)
171-
request.resolve(result)
172-
} else {
173-
request.reject("Location service returned an empty Location array.")
169+
// The capacitor plugin uses locations.first but .last should be the most current one
170+
// and i don't see a reason to use old locations
171+
if let location = locations.last {
172+
let result = convertLocation(location)
173+
request.resolve(result)
174+
} else {
175+
request.reject("Location service returned an empty Location array.")
174176
}
175177
}
176178

@@ -194,7 +196,9 @@ class GeolocationPlugin: Plugin, CLLocationManagerDelegate {
194196
}
195197
}
196198

197-
public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
199+
public func locationManager(
200+
_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus
201+
) {
198202
let requests = self.permissionRequests
199203
self.permissionRequests.removeAll()
200204

plugins/nfc/ios/Sources/NfcPlugin.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ enum ScanKind: Decodable {
1616

1717
struct ScanOptions: Decodable {
1818
let kind: ScanKind
19-
let keepSessionAlive: Bool?
20-
let message: String?
21-
let successMessage: String?
19+
var keepSessionAlive: Bool?
20+
var message: String?
21+
var successMessage: String?
2222
}
2323

2424
struct NDEFRecord: Decodable {
25-
let format: UInt8?
26-
let kind: [UInt8]?
27-
let identifier: [UInt8]?
28-
let payload: [UInt8]?
25+
var format: UInt8?
26+
var kind: [UInt8]?
27+
var identifier: [UInt8]?
28+
var payload: [UInt8]?
2929
}
3030

3131
struct WriteOptions: Decodable {
32-
let kind: ScanKind?
32+
var kind: ScanKind?
3333
let records: [NDEFRecord]
34-
let message: String?
35-
let successMessage: String?
36-
let successfulReadMessage: String?
34+
var message: String?
35+
var successMessage: String?
36+
var successfulReadMessage: String?
3737
}
3838

3939
enum TagProcessMode {

plugins/notification/ios/Sources/NotificationHandler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class NotificationHandler: NSObject, NotificationHandlerProtocol {
3434
try? self.plugin?.trigger("notification", data: notificationData)
3535

3636
if let options = notificationsMap[notification.request.identifier] {
37-
if options.silent {
37+
if options.silent ?? false {
3838
return UNNotificationPresentationOptions.init(rawValue: 0)
3939
}
4040
}

plugins/notification/ios/Sources/NotificationPlugin.swift

+18-18
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ enum ScheduleEveryKind: String, Decodable {
3434
}
3535

3636
struct ScheduleInterval: Decodable {
37-
let year: Int?
38-
let month: Int?
39-
let day: Int?
40-
let weekday: Int?
41-
let hour: Int?
42-
let minute: Int?
43-
let second: Int?
37+
var year: Int?
38+
var month: Int?
39+
var day: Int?
40+
var weekday: Int?
41+
var hour: Int?
42+
var minute: Int?
43+
var second: Int?
4444
}
4545

4646
enum NotificationSchedule: Decodable {
@@ -67,13 +67,13 @@ struct Notification: Decodable {
6767
var title: String
6868
var body: String?
6969
var extra: [String: String]?
70-
let schedule: NotificationSchedule?
71-
let attachments: [NotificationAttachment]?
72-
let sound: String?
73-
let group: String?
74-
let actionTypeId: String?
75-
let summary: String?
76-
var silent = false
70+
var schedule: NotificationSchedule?
71+
var attachments: [NotificationAttachment]?
72+
var sound: String?
73+
var group: String?
74+
var actionTypeId: String?
75+
var summary: String?
76+
var silent: Bool?
7777
}
7878

7979
struct RemoveActiveNotification: Decodable {
@@ -130,19 +130,19 @@ struct Action: Decodable {
130130
var foreground: Bool?
131131
var destructive: Bool?
132132
var input: Bool?
133-
let inputButtonTitle: String?
134-
let inputPlaceholder: String?
133+
var inputButtonTitle: String?
134+
var inputPlaceholder: String?
135135
}
136136

137137
struct ActionType: Decodable {
138138
let id: String
139139
let actions: [Action]
140-
let hiddenPreviewsBodyPlaceholder: String?
140+
var hiddenPreviewsBodyPlaceholder: String?
141141
var customDismissAction: Bool?
142142
var allowInCarPlay: Bool?
143143
var hiddenPreviewsShowTitle: Bool?
144144
var hiddenPreviewsShowSubtitle: Bool?
145-
let hiddenBodyPlaceholder: String?
145+
var hiddenBodyPlaceholder: String?
146146
}
147147

148148
struct RegisterActionTypesArgs: Decodable {

shared/template/ios/Sources/ExamplePlugin.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import UIKit
88
import WebKit
99

1010
class PingArgs: Decodable {
11-
let value: String?
11+
var value: String?
1212
}
1313

1414
class ExamplePlugin: Plugin {

0 commit comments

Comments
 (0)