Summary of extensions added in IOS8 (ii)

Source: Internet
Author: User

    • Share extensions

Note: This tutorial is from Http://www.raywenderlich.com's iOS8 by tutorials

1. Preparation

This example comes from a foreign image sharing site imgur.com

First of all, now Imgur register your account, followed by the following steps, click Settings Select Applications New app, that is, the following create your own, Here the app is I have to demo after click Register your app to enter your app's name after selecting the second item, followed by your mailbox and face, click submit here please remember the app's client ID and client secret to this, register the app successfully , you can call Imgur's API in your app

2. Set up the sharing extension before opening the source jmimgure_original, this is I have not set up the source of share extension, you can do the following process all over again, but only if you need to change the group ID and client ID at the warning to your own, Otherwise it will be an error!!! Here's what you need to be aware of to create your own group ID: and the following source code section:
1 //APPDELEGATE.M2-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {3   //Override point for customization after application launch.4 #warningSet to your client ID here5[Rwtimgurservice Setclientid:@"CLIENT ID"];6   7 [[Uitabbar appearance] Settintcolor:[uicolor Imgvuegreen]];8 [[Uinavigationbar appearance] Settintcolor:[uicolor Imgvuegreen]];9 [[Uiprogressview appearance] Settintcolor:[uicolor Imgvuegreen]];Ten    One   returnYES; A } -  - //RWTSAVEDIMAGESERVICE.M the-(Nsurl *) Urlfordirectorywithname: (NSString *) name { - #warningSet your app GROUP ID here -Nsurl *containerurl = [[Nsfilemanager Defaultmanager] Containerurlforsecurityapplicationgroupidentifier:@"Group.qq100858433.JMImgvue"]; -Containerurl =[Containerurl urlbyappendingpathcomponent:name]; +    -   if(![[Nsfilemanager Defaultmanager] FileExistsAtPath:containerURL.path]) { + [[Nsfilemanager Defaultmanager] createdirectoryaturl:containerurl withintermediatedirectories:no attributes: Nil Error:nil]; A   } at    -   returnContainerurl; -}

3. If the text is already working properly, then you can share the extension settings first, then add share Extension to enter the app share name, click Finish, click Activate, and then set the app for share extension. Groups below we look at the share folder below the info file in the Nsextension entry, the system defaults to the following concerns is nsextensionactivationrule,apple default is set to Truepredicate, This extension will always work, this is convenient and development, but in practice Apple does not allow this value by default, the most basic requirement of app extension is lightweight, so if you directly default, submit to the App Store will not be over the trial, Here we do this change means that each selection of attachments can only choose one, here is set up a place, more about Nsextension click here: App Extension Keysfollowing the implementation of the extension, Apple provides the default class as Slcomposeserviceviewcontroller, which is made to resemble Sina Weibo

Direct use, before the Sharviewcontroller programming, because we want to use the original header files and third-party libraries, so the cocoapods podfile file to make the following changes to increase your build extension project

1# Uncomment ThisLine to define aGlobalPlatform foryour project2# Platform:ios,'6.0'3inhibit_all_warnings!4 5Target'jmimgure'  Do6 7Pod'Sdwebimage'8Pod'afnetworking'9 Ten End One  ATarget'jmimgure Share'  Do -  -Pod'Sdwebimage' thePod'afnetworking' -  -End

Then run the pod install again at the command line, the next face is the changed shareviewcontroller.m, there are notes

1 //2 //SHAREVIEWCONTROLLER.M3 //jmimgure Share4 //5 //Created by Jackma on 15/11/29.6 //copyright©2015 year Jackma. All rights reserved.7 //8 9 #import<MobileCoreServices/MobileCoreServices.h>Ten #import "ShareViewController.h" One  A @interfaceShareviewcontroller () -  -@property (nonatomic, strong) UIImage *image; the  - @end -  - @implementationShareviewcontroller +  -- (void) Viewdidload { +   //get Inputitems, here Itemprovider is the picture you want to share ANsextensionitem *firstitem =Self.extensionContext.inputItems.firstObject; atNsitemprovider *Itemprovider; -   if(FirstItem) { -Itemprovider =FirstItem.attachments.firstObject; -   } -  -   //here Kuttypeimage refers to @ "Public.image", which is the type of picture obtained from the album in   //the kuttypeurl here refers to a link to a website that, if opened in Safari, should be copied to save the current page. -   if([Itemprovider hasitemconformingtotypeidentifier: (NSString *) {Kuttypeurl]) { to[Itemprovider loaditemfortypeidentifier: (NSString *) Kuttypeurl Options:nil completionhandler:^ (ID<NSSecureCoding> _nullable Item, Nserror *_null_unspecified Error) { +       if(!error) { -         //parsing of URLs carried by Itemprovider theNsurl *url = (Nsurl *) Item; *[Uipasteboard Generalpasteboard]. URL =URL; $       }Panax Notoginseng     }]; -   } the   if([Itemprovider hasitemconformingtotypeidentifier: (NSString *) {Kuttypeimage]) { +[Itemprovider loaditemfortypeidentifier: (NSString *) kuttypeimage Options:nil completionhandler:^ (ID<NSSecureCoding> _nullable Item, Nserror *_null_unspecified Error) { A       if(!error) { the         //analysis of pictures carried by Itemprovider +Nsurl *url = (Nsurl *) Item; -NSData *imagedata =[NSData Datawithcontentsofurl:url]; $Self.image =[UIImage Imagewithdata:imagedata]; $       } -     }]; -   } the } - Wuyi //set the post to be valid and call this method every time you enter content the-(BOOL) iscontentvalid { -   if(self.image) { Wu     returnYES; -}Else { About     returnNO; $   } - } -  - //set the action after clicking Post A- (void) Didselectpost { + [self shareimage]; the } -  $ //set the bottom of the pop-up sheet here, asking for Slcomposesheetconfigurationitem objects the-(Nsarray *) Configurationitems { theSlcomposesheetconfigurationitem *configitem =[[Slcomposesheetconfigurationitem alloc] init]; theConfigitem.title =@"the link will be copied to the Clipboard"; the   return@[configitem]; - } in  the- (void) Shareimage { the   //Write the image upload code here About}

Select photos run at runtime

At this point, the most basic settings for sharing extensions have been completed. Source code has original version (original) and set up share version for reference.

SOURCE Click here

Summary of extensions added in IOS8 (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.