Home:ALL Converter>IOS Swift 4 AppDelegate application to handle receiving a custom URL AirDrop file not being hit

IOS Swift 4 AppDelegate application to handle receiving a custom URL AirDrop file not being hit

Ask Time:2020-12-13T06:19:06         Author:kbjb

Json Formatter

My iPhone app sends a custom URL file via AirDrop to my iPad app. The URL has an extension of .fdre. When sent the iPad app opens. However, Application function to handle receiving the custom file in AppDelegate never seems to get hit. Any help would be greatly appreciated.

I have this in my "sending" app:

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)
}

I have this in the AppDelegate of my receiving app:

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

I have this in my receiving app for the document types:

Document Types

cheers kbjb

Author:kbjb,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/65270421/ios-swift-4-appdelegate-application-to-handle-receiving-a-custom-url-airdrop-fil
yy