Monika Patel
Monika Patel

Reputation: 2375

Implementing Namedrop feature in Swift

I want to share a FileURL with Namedrop in iOS 17, but the following code is not working.

I have used UIActivityViewController.

let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = aView // so that iPads won't crash
present(activityViewController, animated: true, completion: nil)

Upvotes: -1

Views: 881

Answers (1)

Monika Patel
Monika Patel

Reputation: 2375

By using this code, you can share a contact.vcf, a URL, an image, or any data via NameDrop on iOS 17 or later. Simply replace the 'fileURL' as needed." just replace the fileURL based on your requirement.

let configuration = UIActivityItemsConfiguration(objects: [fileURL as NSURL])
self.activityItemsConfiguration = configuration
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)

Upvotes: 1

Related Questions