I am working on an app where data (custom structs) can be transfered between instances of the app running on different phones. The app should be able to open Share Sheet and send the data to another device where it will automatically open the app for the data to be imported. (Having support for the share sheet is important because the app needs to be functional when there is not internet access and airdrop seems to be the only way to transfer data between phone when there is no internet.)
So far I have made the struct I would like to transfer between instances of the app conform to the Transferrable Protocol. I have also defined a custom Uniform Type Identifier in the code and the info.plist. With this, I am able to export the struct using the share sheet and it sends a json file ending in .stageresult. However, my issue is that when other devices receive the file they do not open it automatically nor do they give any way to do it manually. Also, I have been unable to find anything online about how to handle importing custom files. Is there a way I can call a function with the imported data to load it into my app? What is the proper way to handle importing custome universal type identifers using Swift/SwiftUI
import UniformTypeIdentifiers
import SwiftUI
import Foundation
extension UTType {
static var stageresult: UTType { UTType(exportedAs: "com.example.stageresult") }
}
struct StageResult: Codable {
var name: String
var start: Bool
var recordings: [Recording]
}
struct Recording: Codable {
var plate: String
var timestamp: Double
}
extension StageResult: Transferable {
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .stageresult)
}
}
Defining Type Identifiers Info.plist Supports Opening Documents In Place