Files
QuickDrop/iOSShareExtension/ShareViewController.swift
T

57 lines
1.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ShareViewController.swift
// iOSShareExtension
//
// Created by Leon Böttger on 17.08.25.
//
import UIKit
import SwiftUI
import LUI
class ShareViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
loadAttachments(with: extensionContext, loadedItems: { [self] result in
log("ShareViewController: Loaded attachments: \(result)")
var attachmentDetails = result
attachmentDetails.closeView = { [weak self] in
// Close the extension view
self?.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}
DispatchQueue.main.async {
NearbyConnectionManager.shared.attachments = attachmentDetails
}
})
// skip introduction for share extension
LUIInit(configuration: configuration)
LUISettings.sharedInstance.appLaunchedBefore = true
// Replace with your app’s SwiftUI entry view
let contentView = ContentView()
// Embed SwiftUI inside the extension’s controller
let hostingController = UIHostingController(rootView: contentView)
addChild(hostingController)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(hostingController.view)
// Pin to edges
NSLayoutConstraint.activate([
hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
hostingController.didMove(toParent: self)
}
}