首页 > 解决方案 > IOS Swift 4 AppDelegate 应用程序处理接收自定义 URL AirDrop 文件未命中

问题描述

我的 iPhone 应用程序通过 AirDrop 将自定义 URL 文件发送到我的 iPad 应用程序。该 URL 的扩展名为 .fdre。发送后,iPad 应用程序将打开。但是,在 AppDelegate 中处理接收自定义文件的应用程序函数似乎从未受到影响。任何帮助将不胜感激。

我的“发送”应用程序中有这个:

func exportToURL (data : String) -> URL {
    var input : String = ""
    let url = self.getDocumentsDirectory().appendingPathComponent("FUNduroResult.fdre")

    do {
        try data.write(to: url, atomically: true, encoding: .utf8)
        input = try String(contentsOf: url)
        print(input)
        print(url)
    } catch {
        print(error.localizedDescription)
    }
    return url
}

@IBAction func airdropButton(_ sender: Any) {
    
    let text = formatDataAsCSV()
    
    let url = exportToURL(data: text)
    
    let activity = UIActivityViewController(
      activityItems: ["Check out this result for the FUNduro.", url],
      applicationActivities: nil
    )
    activity.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem

    present(activity, animated: true, completion: nil)
}

我在接收应用程序的 AppDelegate 中有这个:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if url.pathExtension == "fdre" {
        print("got result")
    }
    return true
}

我在我的接收应用程序中有这个文件类型:

文件类型

干杯 kbjb

标签: iosswiftairdropuiactivitytypeairdrop

解决方案


推荐阅读