|
...
|
...
|
@@ -98,6 +98,26 @@ final class PlatformHostApiImpl: PlatformHostApi { |
|
|
|
UIApplication.shared.open(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func shareText(text: String, completion: @escaping (Result<Bool, any Error>) -> Void) {
|
|
|
|
presentShareSheet(items: [text], completion: completion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func shareFileData(databytes: FlutterStandardTypedData, completion: @escaping (Result<Bool, any Error>) -> Void) {
|
|
|
|
let fileURL = FileManager.default.temporaryDirectory
|
|
|
|
.appendingPathComponent("doublefeel-share-\(UUID().uuidString)")
|
|
|
|
.appendingPathExtension("data")
|
|
|
|
|
|
|
|
do {
|
|
|
|
try databytes.data.write(to: fileURL, options: .atomic)
|
|
|
|
} catch {
|
|
|
|
print("[PlatformHostApiImpl.shareFileData] return error: \(error)")
|
|
|
|
completion(.failure(error))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
presentShareSheet(items: [fileURL], cleanupURL: fileURL, completion: completion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func uploadFile(filePath: String, resourceType: HResourceType, completion: @escaping (Result<String?, any Error>) -> Void) {
|
|
|
|
let obsResourceType: HuaweiOBSResourceType
|
|
...
|
...
|
@@ -274,3 +294,73 @@ final class PlatformHostApiImpl: PlatformHostApi { |
|
|
|
return userAgent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//MARK: - 分享
|
|
|
|
extension PlatformHostApiImpl{
|
|
|
|
private func presentShareSheet(
|
|
|
|
items: [Any],
|
|
|
|
cleanupURL: URL? = nil,
|
|
|
|
completion: @escaping (Result<Bool, any Error>) -> Void
|
|
|
|
) {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
guard let viewController = Self.topViewController() else {
|
|
|
|
if let cleanupURL {
|
|
|
|
try? FileManager.default.removeItem(at: cleanupURL)
|
|
|
|
}
|
|
|
|
let error = NSError(
|
|
|
|
domain: "PlatformHostApiImpl.Share",
|
|
|
|
code: 1,
|
|
|
|
userInfo: [NSLocalizedDescriptionKey: "Unable to find a view controller for sharing."]
|
|
|
|
)
|
|
|
|
print("[PlatformHostApiImpl.share] return error: \(error)")
|
|
|
|
completion(.failure(error))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let activityController = UIActivityViewController(
|
|
|
|
activityItems: items,
|
|
|
|
applicationActivities: nil
|
|
|
|
)
|
|
|
|
activityController.popoverPresentationController?.sourceView = viewController.view
|
|
|
|
activityController.popoverPresentationController?.sourceRect = CGRect(
|
|
|
|
x: viewController.view.bounds.midX,
|
|
|
|
y: viewController.view.bounds.midY,
|
|
|
|
width: 1,
|
|
|
|
height: 1
|
|
|
|
)
|
|
|
|
activityController.completionWithItemsHandler = { _, completed, _, error in
|
|
|
|
if let cleanupURL {
|
|
|
|
try? FileManager.default.removeItem(at: cleanupURL)
|
|
|
|
}
|
|
|
|
if let error {
|
|
|
|
print("[PlatformHostApiImpl.share] return error: \(error)")
|
|
|
|
completion(.failure(error))
|
|
|
|
} else {
|
|
|
|
print("[PlatformHostApiImpl.share] return: \(completed)")
|
|
|
|
completion(.success(completed))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
viewController.present(activityController, animated: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static func topViewController(
|
|
|
|
from rootViewController: UIViewController? = UIApplication.shared.connectedScenes
|
|
|
|
.compactMap { $0 as? UIWindowScene }
|
|
|
|
.first(where: { $0.activationState == .foregroundActive })?
|
|
|
|
.windows
|
|
|
|
.first(where: { $0.isKeyWindow })?
|
|
|
|
.rootViewController
|
|
|
|
) -> UIViewController? {
|
|
|
|
if let presented = rootViewController?.presentedViewController {
|
|
|
|
return topViewController(from: presented)
|
|
|
|
}
|
|
|
|
if let navigationController = rootViewController as? UINavigationController {
|
|
|
|
return topViewController(from: navigationController.visibleViewController)
|
|
|
|
}
|
|
|
|
if let tabBarController = rootViewController as? UITabBarController {
|
|
|
|
return topViewController(from: tabBarController.selectedViewController)
|
|
|
|
}
|
|
|
|
return rootViewController
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|