IOS8 new feature extension (Extension) application three--Photo editor Plugin
with the introduction of the previous blogs, we learned that the extended interactive capabilities offered by the app are more powerful, and this powerful interactivity is reflected in the application of the photo editing plugin.
As usual, let's create a project and then a new target, select photo editing:
From the template, we can see that the system has created a controller for us, which is the controller used to process the photo, with the following methods:
- (BOOL) Canhandleadjustmentdata: (phadjustmentdata *) adjustmentdata { // Inspect the adjustmentData to determine whether your extension can work with past edits. // (Typically, you use its formatidentifier and formatversion properties to do this.) return no;} This function is used to get the selected photo from the system album, the data type that contains the response in the Contenteditinginput object, and the image object- (void) Startcontenteditingwithinput: ( phcontenteditinginput *) Contenteditinginput placeholderimage: (uiimage *) placeholderImage { //we can get the data to show here and so on self.input = contenteditinginput;} Method- (void) Finishcontenteditingwithcompletionhandler when editing a photo: (void (^) (phcontenteditingoutput *)) completionhandler { // update ui to reflect that editing has finished and output is being rendered. // Render and provide output on a Background queue. dispatch_async (Dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY _default, 0), ^{ // create editing output from the editing input. phcontenteditingoutput *output = [[phcontenteditingoutput alloc] initwithcontenteditinginput:self.input]; //we can write new picture data into the output stream here // output.adjustmentdata = < #new adjustment data#>; // nsdata *renderedjpegdata = < #output JPEG#>; // [renderedJPEGData writetourl:output.renderedcontenturl atomically:yes]; // call completion handler to commit edit to photos. completionhandler (output); // clean up temporary files, etc. });}
Before the end of the current extension execution, we are free to render the images we get, such as adding frames, text, etc., and outputting the rendered image after the output.
There's another place we need to be aware that this kind of extension has a function, if we exit the editor halfway, the system will save our extended processing state for us, in order to distinguish multiple similar functions of the extension, in the output data of the object has a An object of type Phadjustmentdata that is dedicated to the record of the version, which has the following two attributes to differentiate the version:
@property (readonly, copy) nsstring *formatidentifier;
@property (readonly, copy) nsstring *formatversion;
IOS8 new feature extension (Extension) application three--Photo editor Plugin