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

321 views Asked by At

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

0

There are 0 answers