Skip to content

Commit

Permalink
chore(ios): consolidate optional argument standard (#1738)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lucasfernog authored Sep 10, 2024
1 parent 713c54e commit a34fade
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 60 deletions.
14 changes: 8 additions & 6 deletions examples/api/src-tauri/Info.plist
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSCameraUsageDescription</key>
<string>Request camera access for WebRTC</string>
<key>NSMicrophoneUsageDescription</key>
<string>Request microphone access for WebRTC</string>
</dict>
<dict>
<key>NSCameraUsageDescription</key>
<string>Request camera access for WebRTC</string>
<key>NSMicrophoneUsageDescription</key>
<string>Request microphone access for WebRTC</string>
<key>NSFaceIDUsageDescription</key>
<string>Authenticate with biometrics</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions examples/api/src-tauri/gen/apple/api_iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSFaceIDUsageDescription</key>
<string>Authenticate with biometrics</string>
<key>NSCameraUsageDescription</key>
<string>Request camera access for WebRTC</string>
<key>NSMicrophoneUsageDescription</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions plugins/biometric/ios/Sources/BiometricPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 23 additions & 19 deletions plugins/geolocation/ios/Sources/GeolocationPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
}
}

Expand All @@ -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()

Expand Down
22 changes: 11 additions & 11 deletions plugins/nfc/ios/Sources/NfcPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion plugins/notification/ios/Sources/NotificationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
36 changes: 18 additions & 18 deletions plugins/notification/ios/Sources/NotificationPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion shared/template/ios/Sources/ExamplePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
import WebKit

class PingArgs: Decodable {
let value: String?
var value: String?
}

class ExamplePlugin: Plugin {
Expand Down

0 comments on commit a34fade

Please sign in to comment.