From a34fade5004a64f1b00c39a34397f18c65bb625e Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 10 Sep 2024 08:31:39 -0300 Subject: [PATCH] chore(ios): consolidate optional argument standard (#1738) * chore(ios): consolidate optional argument standard mark all optional iOS arguments as `var : Type?`, following the pattern described in the documentation: https://v2.tauri.app/develop/plugins/develop-mobile/#ios * chore: add missing Info.plist to example --- examples/api/src-tauri/Info.plist | 14 ++++--- .../src-tauri/gen/apple/api_iOS/Info.plist | 2 + .../ios/Sources/BarcodeScannerPlugin.swift | 4 +- .../ios/Sources/BiometricPlugin.swift | 4 +- .../ios/Sources/GeolocationPlugin.swift | 42 ++++++++++--------- plugins/nfc/ios/Sources/NfcPlugin.swift | 22 +++++----- .../ios/Sources/NotificationHandler.swift | 2 +- .../ios/Sources/NotificationPlugin.swift | 36 ++++++++-------- .../template/ios/Sources/ExamplePlugin.swift | 2 +- 9 files changed, 68 insertions(+), 60 deletions(-) diff --git a/examples/api/src-tauri/Info.plist b/examples/api/src-tauri/Info.plist index fe253ec7..c20d8946 100644 --- a/examples/api/src-tauri/Info.plist +++ b/examples/api/src-tauri/Info.plist @@ -1,10 +1,12 @@ - - NSCameraUsageDescription - Request camera access for WebRTC - NSMicrophoneUsageDescription - Request microphone access for WebRTC - + + NSCameraUsageDescription + Request camera access for WebRTC + NSMicrophoneUsageDescription + Request microphone access for WebRTC + NSFaceIDUsageDescription + Authenticate with biometrics + diff --git a/examples/api/src-tauri/gen/apple/api_iOS/Info.plist b/examples/api/src-tauri/gen/apple/api_iOS/Info.plist index 2106cfb6..31966590 100644 --- a/examples/api/src-tauri/gen/apple/api_iOS/Info.plist +++ b/examples/api/src-tauri/gen/apple/api_iOS/Info.plist @@ -40,6 +40,8 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + NSFaceIDUsageDescription + Authenticate with biometrics NSCameraUsageDescription Request camera access for WebRTC NSMicrophoneUsageDescription diff --git a/plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift b/plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift index ec16ad59..7efdc256 100644 --- a/plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift +++ b/plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift @@ -9,8 +9,8 @@ import WebKit struct ScanOptions: Decodable { var formats: [SupportedFormat]? - let windowed: Bool? - let cameraDirection: String? + var windowed: Bool? + var cameraDirection: String? } enum SupportedFormat: String, CaseIterable, Decodable { diff --git a/plugins/biometric/ios/Sources/BiometricPlugin.swift b/plugins/biometric/ios/Sources/BiometricPlugin.swift index 7e3e8bbd..3c9a192a 100644 --- a/plugins/biometric/ios/Sources/BiometricPlugin.swift +++ b/plugins/biometric/ios/Sources/BiometricPlugin.swift @@ -25,8 +25,8 @@ class BiometricStatus { struct AuthOptions: Decodable { let reason: String var allowDeviceCredential: Bool? - let fallbackTitle: String? - let cancelTitle: String? + var fallbackTitle: String? + var cancelTitle: String? } class BiometricPlugin: Plugin { diff --git a/plugins/geolocation/ios/Sources/GeolocationPlugin.swift b/plugins/geolocation/ios/Sources/GeolocationPlugin.swift index fedfa570..7a2b57a9 100644 --- a/plugins/geolocation/ios/Sources/GeolocationPlugin.swift +++ b/plugins/geolocation/ios/Sources/GeolocationPlugin.swift @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +import CoreLocation import SwiftRs import Tauri import UIKit import WebKit -import CoreLocation class GetPositionArgs: Decodable { - let enableHighAccuracy: Bool? + var enableHighAccuracy: Bool? } class WatchPositionArgs: Decodable { @@ -101,14 +101,14 @@ class GeolocationPlugin: Plugin, CLLocationManagerDelegate { if CLLocationManager.locationServicesEnabled() { // TODO: Use the authorizationStatus instance property with locationManagerDidChangeAuthorization(_:) instead. switch CLLocationManager.authorizationStatus() { - case .notDetermined: - status = "prompt" - case .restricted, .denied: - status = "denied" - case .authorizedAlways, .authorizedWhenInUse: - status = "granted" - @unknown default: - status = "prompt" + case .notDetermined: + status = "prompt" + case .restricted, .denied: + status = "denied" + case .authorizedAlways, .authorizedWhenInUse: + status = "granted" + @unknown default: + status = "prompt" } } else { invoke.reject("Location services are not enabled.") @@ -161,16 +161,18 @@ class GeolocationPlugin: Plugin, CLLocationManagerDelegate { } } - public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + public func locationManager( + _ manager: CLLocationManager, didUpdateLocations locations: [CLLocation] + ) { // Respond to all getCurrentPosition() calls. for request in self.positionRequests { - // The capacitor plugin uses locations.first but .last should be the most current one - // and i don't see a reason to use old locations - if let location = locations.last { - let result = convertLocation(location) - request.resolve(result) - } else { - request.reject("Location service returned an empty Location array.") + // The capacitor plugin uses locations.first but .last should be the most current one + // and i don't see a reason to use old locations + if let location = locations.last { + let result = convertLocation(location) + request.resolve(result) + } else { + request.reject("Location service returned an empty Location array.") } } @@ -194,7 +196,9 @@ class GeolocationPlugin: Plugin, CLLocationManagerDelegate { } } - public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { + public func locationManager( + _ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus + ) { let requests = self.permissionRequests self.permissionRequests.removeAll() diff --git a/plugins/nfc/ios/Sources/NfcPlugin.swift b/plugins/nfc/ios/Sources/NfcPlugin.swift index 21bb2606..58d69a84 100644 --- a/plugins/nfc/ios/Sources/NfcPlugin.swift +++ b/plugins/nfc/ios/Sources/NfcPlugin.swift @@ -16,24 +16,24 @@ enum ScanKind: Decodable { struct ScanOptions: Decodable { let kind: ScanKind - let keepSessionAlive: Bool? - let message: String? - let successMessage: String? + var keepSessionAlive: Bool? + var message: String? + var successMessage: String? } struct NDEFRecord: Decodable { - let format: UInt8? - let kind: [UInt8]? - let identifier: [UInt8]? - let payload: [UInt8]? + var format: UInt8? + var kind: [UInt8]? + var identifier: [UInt8]? + var payload: [UInt8]? } struct WriteOptions: Decodable { - let kind: ScanKind? + var kind: ScanKind? let records: [NDEFRecord] - let message: String? - let successMessage: String? - let successfulReadMessage: String? + var message: String? + var successMessage: String? + var successfulReadMessage: String? } enum TagProcessMode { diff --git a/plugins/notification/ios/Sources/NotificationHandler.swift b/plugins/notification/ios/Sources/NotificationHandler.swift index 83ac0ae4..1bf134b6 100644 --- a/plugins/notification/ios/Sources/NotificationHandler.swift +++ b/plugins/notification/ios/Sources/NotificationHandler.swift @@ -34,7 +34,7 @@ public class NotificationHandler: NSObject, NotificationHandlerProtocol { try? self.plugin?.trigger("notification", data: notificationData) if let options = notificationsMap[notification.request.identifier] { - if options.silent { + if options.silent ?? false { return UNNotificationPresentationOptions.init(rawValue: 0) } } diff --git a/plugins/notification/ios/Sources/NotificationPlugin.swift b/plugins/notification/ios/Sources/NotificationPlugin.swift index 9371e83d..6d8391bc 100644 --- a/plugins/notification/ios/Sources/NotificationPlugin.swift +++ b/plugins/notification/ios/Sources/NotificationPlugin.swift @@ -34,13 +34,13 @@ enum ScheduleEveryKind: String, Decodable { } struct ScheduleInterval: Decodable { - let year: Int? - let month: Int? - let day: Int? - let weekday: Int? - let hour: Int? - let minute: Int? - let second: Int? + var year: Int? + var month: Int? + var day: Int? + var weekday: Int? + var hour: Int? + var minute: Int? + var second: Int? } enum NotificationSchedule: Decodable { @@ -67,13 +67,13 @@ struct Notification: Decodable { var title: String var body: String? var extra: [String: String]? - let schedule: NotificationSchedule? - let attachments: [NotificationAttachment]? - let sound: String? - let group: String? - let actionTypeId: String? - let summary: String? - var silent = false + var schedule: NotificationSchedule? + var attachments: [NotificationAttachment]? + var sound: String? + var group: String? + var actionTypeId: String? + var summary: String? + var silent: Bool? } struct RemoveActiveNotification: Decodable { @@ -130,19 +130,19 @@ struct Action: Decodable { var foreground: Bool? var destructive: Bool? var input: Bool? - let inputButtonTitle: String? - let inputPlaceholder: String? + var inputButtonTitle: String? + var inputPlaceholder: String? } struct ActionType: Decodable { let id: String let actions: [Action] - let hiddenPreviewsBodyPlaceholder: String? + var hiddenPreviewsBodyPlaceholder: String? var customDismissAction: Bool? var allowInCarPlay: Bool? var hiddenPreviewsShowTitle: Bool? var hiddenPreviewsShowSubtitle: Bool? - let hiddenBodyPlaceholder: String? + var hiddenBodyPlaceholder: String? } struct RegisterActionTypesArgs: Decodable { diff --git a/shared/template/ios/Sources/ExamplePlugin.swift b/shared/template/ios/Sources/ExamplePlugin.swift index 36c3a8f7..2a1055de 100644 --- a/shared/template/ios/Sources/ExamplePlugin.swift +++ b/shared/template/ios/Sources/ExamplePlugin.swift @@ -8,7 +8,7 @@ import UIKit import WebKit class PingArgs: Decodable { - let value: String? + var value: String? } class ExamplePlugin: Plugin {