The OSSharing class provides support for printing and sharing content from your app.
Load() This event is called when the object becames available in the current runtime system.
Unload() This event is called when the object has been removed from the current runtime system (but not yet deallocated).
- var isPrintingAvailable: Bool Returns a Boolean indicating whether the device supports printing.
var items: List The array of data objects on which to perform the activity. The type of objects in the array is variable and dependent on the data your application manages. For example, the data might consist of one or more string or image objects representing the currently selected content.
var objectName: String The name of the object.
func shareImage(image: Image) Share image with others apps.
func shareData(data: Data) Share raw data with others apps.
func shareString(string: String) Share a string with others apps.
func shareURL(string: String) Share URL with others apps.
func show() Display sharing dialog to the user.
func addExcludedType(options: Int) Add a service that you do not want displayed to the user. You might exclude services that you feel are not suitable for the content you are providing. For example, you might not want to allow the user to print a specific image. If the value of this property is nil, no services are excluded.
func printImage(image: Image) Presents the printing user interface in a sheet to print an image.
func printText(text: String) Presents the printing user interface in a sheet to print a String.
func printMarkupText(text: String) Presents the printing user interface in a sheet to print a Markup String.
func printData(data: Data) Presents the printing user interface in a sheet to print Data.
func printItem(item: Object) Presents the printing user interface in a sheet to print an item (can be an URL, a path, a TextView, a MapView or a WebView.
func printFile(path: String) Presents the printing user interface in a sheet to print a file.
func printItems(items: List) Presents the printing user interface in a sheet to print a List of items (usually a sequence of Images).
Share an Image:
var image = MyGreatImage; OSSharing.shareImage(image);
Share a String:
var s = "Hello World"; OSSharing.shareString(s);
Share an Image and a String:
var image = MyGreatImage; var s = "Hello World"; var share: OSSharing = OSSharing(); share.items = [image, s]; share.show();
Share a URL:
var url= "https://creolabs.com"; OSSharing.shareURL(url);
Add my app to the sharing menu to receive shared URLs:
If you want to see your App in the sharing dialog, you need to register the document types that your application can open with iOS. To do this you need to add a document type to your app’s Property List (Main Menu > Project > Properties...) for each document type that your app can open. Additionally, if any of the document types are not known by iOS, you will need to provide an Uniform Type Identifier (UTI) for that document type.
Each document type item should contain a value for the following keys:
CFBundleTypeName(String: the abstract name for the document type).
CFBundleTypeRole(String: The app's role with respect to the document type. Possible values:
LSHandlerRank(String: The ranking of this app among apps that declare themselves as editors or viewers of the given file type. Possible values:
LSItemContentTypes(Array: The document file types the app supports. Each item of the Array must be a String representing an UTI. For example,
Example of the configuration to receive URLs of JPEG images:
Then add your code to process the received URLs in the
OpenUrl event of the
App object, for example:
Window1.ImageView1.url = url
Share a file URL with the JPEG representation of an Image:
// Create the JPEG representation of the image var jpgImage = image.JPEGRepresentation(0.7); // Save the JPEG representation to the file system using a FileManager var fileName = "unique-filename.jpg"; FileManager1.createFile(fileName, jpgImage); // Get the full path of the created file var url : String = FileManager1.path(fileName); // Share the file URL OSSharing.shareURL(url)
For your convenience we create a simple printing test application
- PrintTest.zip (4.2MB)