feat: saveToken plugin for app groups on iOS
This will allow the share extension to access the Bearer token to send images to the backend.
This commit is contained in:
10
tauri-plugin-ios-shared-token/ios/.gitignore
vendored
Normal file
10
tauri-plugin-ios-shared-token/ios/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/config/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
Package.resolved
|
||||
32
tauri-plugin-ios-shared-token/ios/Package.swift
Normal file
32
tauri-plugin-ios-shared-token/ios/Package.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
// swift-tools-version:5.3
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "tauri-plugin-ios-shared-token",
|
||||
platforms: [
|
||||
.macOS(.v10_13),
|
||||
.iOS(.v13),
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "tauri-plugin-ios-shared-token",
|
||||
type: .static,
|
||||
targets: ["tauri-plugin-ios-shared-token"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(name: "Tauri", path: "../.tauri/tauri-api")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "tauri-plugin-ios-shared-token",
|
||||
dependencies: [
|
||||
.byName(name: "Tauri")
|
||||
],
|
||||
path: "Sources")
|
||||
]
|
||||
)
|
||||
3
tauri-plugin-ios-shared-token/ios/README.md
Normal file
3
tauri-plugin-ios-shared-token/ios/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Tauri Plugin ios-shared-token
|
||||
|
||||
A description of this package.
|
||||
34
tauri-plugin-ios-shared-token/ios/Sources/SharedToken.swift
Normal file
34
tauri-plugin-ios-shared-token/ios/Sources/SharedToken.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
import SwiftRs
|
||||
import Tauri
|
||||
import UIKit
|
||||
import WebKit
|
||||
|
||||
class SaveTokenArgs: Decodable {
|
||||
var token: String?
|
||||
}
|
||||
|
||||
let appGroupID = "group.com.haystack.com"
|
||||
let sharedTokenKey = "sharedAuthToken"
|
||||
|
||||
class SharedToken: Plugin {
|
||||
@objc func saveToken(_ invoke: Invoke) throws {
|
||||
guard let args = try? invoke.parseArgs(SaveTokenArgs.self), let token = args.token else {
|
||||
invoke.reject("Missing token argument")
|
||||
return
|
||||
}
|
||||
|
||||
// Access shared UserDefaults
|
||||
guard let sharedDefaults = UserDefaults(suiteName: appGroupID) else {
|
||||
invoke.reject("Could not access shared UserDefaults. Check App Group configuration.")
|
||||
return
|
||||
}
|
||||
|
||||
sharedDefaults.set(token, forKey: sharedTokenKey)
|
||||
invoke.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("init_plugin_ios_shared_token")
|
||||
func initPlugin() -> Plugin {
|
||||
return SharedToken()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import XCTest
|
||||
@testable import ExamplePlugin
|
||||
|
||||
final class ExamplePluginTests: XCTestCase {
|
||||
func testExample() throws {
|
||||
let plugin = ExamplePlugin()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user