Listing 12-1An example implementation of didSelectPostĬalling the completeRequestReturningItems:completionHandler: method can cause the associated compose view controller to be dismissed. Listing 12-1 shows one way to implement the didSelectPost method. Set up a background-mode URL session (using the NSURLSession class) that includes the content to postĬall the completeRequestReturningItems:completionHandler: method, which signals the host app that its original request is complete The system then calls the didSelectPost method of the SLComposeServiceViewController class. When a user chooses the Post or Send button in your Share extension, a system-provided animation provides feedback that the action is being processed. The primary purpose of a Share extension is to help users post content. ![]() If you want to animate the display of your content to coincide with the resize animation, implement viewWillTransitionToSize:withTransitionCoordinator:, using animateAlongsideTransition:completion: to add your animations to the coordinator parameter. If you don’t use Auto Layout, you can use the UIViewController property preferredContentSize to specify the view’s new height. When you have additional content to display, you can rely on Auto Layout constraints to adjust the view’s height as appropriate. For example, you want users to be able to post a simple remark with very little effort, but you may also want to help users preview an attachment, tag a post, or specify details, such as a privacy setting or an album to use. In general, you don’t want to overcomplicate a simple task, but you also want to give users the options they expect. If the system-supplied compose view meets your needs, you don’t need to supply any custom UI. In particular, your Share extension can’t increase in width, and although it may increase in height, you don’t want to force users to scroll too much. The sharing UI on both platforms is constrained in size. When a user chooses Post, a Share extension validates the text view’s content (in addition to attachments, if any) and calls the completeRequestReturningItems:expirationHandler:completion: method of NSExtensionContext, using code like the following:įor best results, use Auto Layout to design a Share extension. The default SLComposeServiceViewController object includes a text view that displays the user’s editable text content. (To learn more about how an extension can interact with its context, see Respond to the Host App’s Request.) The extension context object also contains information about the status of the posting operation. (To learn more about how to use JavaScript to access a webpage, see Accessing a Webpage.) You also add keys and values if you want to specify the data types your extension works with (to learn more, see Declaring Supported Data Types for a Share or Action Extension).Ī Share extension uses its principal view controller’s extensionContext property to get the NSExtensionContext object that contains the user’s initial text and any attachments for a post, such as links, images, or videos. For example, to provide a JavaScript file that accesses a webpage, add the NSExtensionAttributes key and a dictionary that specifies the file. ![]() The Xcode Share template provides default header and implementation files for the principal view controller class (called SharingViewController), an ist file, and an interface file (that is, a storyboard or xib file).ĭepending on the functionality of your Share extension, you might need to add keys and values to the default property list. The system-provided compose view controller builds in some support for common tasks, such as previewing and validating standard items, synchronizing content and view animation, and configuring a post. You can base your view on the system-provided compose view controller, or you can create a completely custom compose view. ![]() When users choose your Share extension, you display a view in which they compose their content and post it. ![]() Select some content, Control-click to reveal a contextual menu, and choose Share. View the Social area in Notification Center. In OS X, users can reveal the list of sharing services in a few different ways. In iOS, users tap the Share button and choose a Share extension from the sharing area of the activity view controller that appears. Users get access to Share extensions in the system-provided UI. You can learn more about specifying content types in Declaring Supported Data Types for a Share or Action Extension. You may want to specify the types of content your Share extension can work with so that users understand what they can share.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |