IOS 8 Share Extension Safari URL Example (Share the url Example in iOS), safariios

Source: Internet
Author: User
Tags url example

IOS 8 Share Extension Safari URL Example (Share the url Example in iOS), safariios
The Extension of ios8 provides us with a lot of amazing functions, and we will no longer need to enter the app for sharing content in the future, making our mobile phones safer, the following describes how Share Extension Works by sharing a web url in safari.

1. Create a Share Extension target referenceHttp://blog.csdn.net/wjsxiaoweige/article/details/39524291Establish phone Extension



2. Configure info. plist in NSExtensionActivationRule. we can add the sharing rules such as nsextensionactivationsuppsimsimagewithmaxcount NSExtensionActivationSupportsMovieWithMaxCount limit to limit the maximum number of shares. If you cannot share a type, you




3. modify the code in render viewcontroller. When sharing the code, let's analyze what our EXtension app will do first.

- (void)viewDidLoad- (BOOL)isContentValid- (void)didSelectPost- (NSArray *)configurationItems


We don't need to talk about the viewDidLoad method. isContentValid is used to determine whether the obtained data is what we want.
DidSelectPost is the method after selection. configurationItems returns only one SLComposeSheetConfigurationItem. This is a list similar to tableview.

After the above three steps can implement a simple share Extension compilation and running, we will see a very simple sharing page. Of course, we haven't done anything yet, so how can we associate the items we want to share with our applications or upload them to our servers?


Which of the following statements about how to share the content of a webpage ______________________


4. First, we need to obtain the data to be shared (the shared webpage is used as an example). First, we need to determine whether the data type is what we want.

- (BOOL)isContentValid {    // Do validation of contentText and/or NSExtensionContext attachments here        NSExtensionItem * imageItem = [self.extensionContext.inputItems firstObject];    if(!imageItem)    {        return NO;    }    NSItemProvider * imageItemProvider = [[imageItem attachments] firstObject];    if(!imageItemProvider)    {        return NO;    }    if([imageItemProvider hasItemConformingToTypeIdentifier:@"public.url"]&&self.contentText)    {        return YES;    }        return YES;}




5. Obtain the data in the viewdidLoad code.
-(Void) viewDidLoad {NSExtensionItem * imageItem = [self. extensionContext. inputItems firstObject]; NSItemProvider * imageItemProvider = [[imageItem attachments] firstObject]; if ([imageItemProvider hasItemConformingToTypeIdentifier :( NSString *) kUTTypeURL]) {NSLog (@ "xxxxxxxx "); [imageItemProvider loadItemForTypeIdentifier :( NSString *) kUTTypeURL options: nil completionHandler: ^ (NSURL * imageUrl, NSError * error) {// here do your own work NSLog (@ "xxxxxxx123 = % @", imageUrl. absoluteString); urlString = imageUrl. absoluteString ;}] ;}}


With the above code, we can get the URL of the page to be shared and save it to urlString.



6. When we click the post method, didSelectPost will be triggered. In this case, we can implement data sharing.

DidSelectPost code implementation

-(Void) didSelectPost {NSExtensionItem * imageItem = [self. extensionContext. inputItems firstObject]; // save some operations and add the http request UIAlertController * alter = [UIAlertController alertControllerWithTitle: @ "11" message: @ "111" preferredStyle: Contents]; [self presentViewController: alter animated: YES completion: ^ {}]; NSExtensionItem * outputItem = [imageItem copy]; outputItem. attributedContentText = [[NSAttributedString alloc] initWithString: self. contentText attributes: nil]; NSArray * outPutitems = @ [outputItem]; [self. extensionContext completeRequestReturningItems: outPutitems completionHandler: nil];}

 



7. The implementation of the configurationItems Code gives us a default method. However, we can choose some content methods, that is, the 123




Click cell 123. A new VC is displayed,



Here I only pop up an empty VC. On this interface, we can add anything we want. Of course, don't add anything too complicated.

The implementation method is as follows:


- (NSArray *)configurationItems {    // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.        SLComposeSheetConfigurationItem * oneItem = [[SLComposeSheetConfigurationItem alloc]init];    oneItem.title = @"123";    oneItem.valuePending = NO;    oneItem.tapHandler = ^(void)    {                        ListViewController * listVC = [[ListViewController alloc] init];             [self pushConfigurationViewController:listVC];            };           return @[oneItem];}




OK





Why is the URL displayed in Safari for iOS 7 maliciously pointing to Baidu? (IPad Air)

If there is a picture and there is a truth, give it to the picture ~

If the iOS60 device fails to be activated, the system prompts "this device is not registered as part of the iPhone development program and requires the developer ID to be registered at @ url"

In fact, the problem is very simple. It doesn't have much to do with iOS 6 or 5. Don't think about it too complicated. You should first conquer the problem. Modify the host file to solve the 3194 problem and check whether itunes can restore the device. No more, follow the program strictly to enter the DFU mode for recovery. I can't use a small umbrella to build a server. The last thing you can do is send it to after-sales personnel. Strictly speaking, if you do not jailbreak, the iOS 6 you just use should not be damaged. After all, iOS 6 is also a genuine product of apple, but it is still a test version for developers. Don't worry. A single department will always find the root cause of the problem and solve it by finding the root cause.

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.