![]() let url URL (string: shareUrlString) let text 'Some text that you want shared' let activity UIActivityViewController (activityItems: url, text, applicationActivities: nil) present (activity, animated: true) Share. ![]() I connected the label to an outlet and the button to an action. Simplified solution working with Swift 5+. I added a button and a label to my root view controller. I had to run it a couple times in the simulator before it worked because it was timing out. UIActivityViewController Not Sharing Both URL & Text in Messages. Clicking 'Share some text' gives result on the left and clicking 'Share an image' gives the result on the right. Fill the file with some text, it can be anything you want. Swift: Setting Email Recipients in UIActivityViewController Add subject on email by. For simplicity, I'll use a plain text file with a custom extension.Īdd plain file to project and give it name: fileToShare.shr. let url URL(string:self. is the easiest way to let users share content like text and URLs. In iOS 13, you can easily accomplish this with the share sheet. We will make the app create and open the new file. SwiftUIs coordinators are designed to act as delegates for UIKit view controllers. This will ensure, that system will list our app when opening a new custom type. Expand Document Types and add entry: New document type UIActivityViewController makes sharing easy and it allows one to share many different types content including, text, images, URLs, Audio and more. 1: If the file is pre loaded then access their file path by giving their name ex:abc. here I have taken PDF file which has to share. Apple provides many more types, available here. Sometimes we need to share the local file or from url. Those are the vaguest types, perfect for our demo. ![]() For example, a PDF file contains both text and special formatting data. public.data - Base physical type for byte streams (flat files, pasteboard data, and so on).This component is called UIActivityViewController: you tell it what kind of data you want to share, and it figures out how best to share it. As a result, it should be your first port of call when adding sharing to an app. Open Info page of your target: Info page in XcodeĮxpand Exported Type Identifiers and add a new entry: Exported type identifierĪpple documentation clearly stays, that our new type has to conform to at least one public type. Sharing things using iOS uses a standard, powerful component that other apps can plug into. ![]() If you are planning to share more than standard file types on iOS and make the system recognize the file and open it in your app you can use Document Types and Exported Type Identifiers.įor some time, Xcode is making a declaration of custom types easy. ![]()
0 Comments
Leave a Reply. |