Share Extension Programming

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sinat_30657013/article/details/62889849

Share Extension programming, you can quickly share a link to your App in Safari.


Creation process is similar to Today, however much introduction, said that under the main built-in method:

- (void)viewDidLoad {

    NSLog(@"viewDidLoad");

    self.view.hidden = YES;

    // share information

    [ Themselves share information ];

}

// sharing content whether it is in line with the requirements of

- (BOOL)isContentValid {

    // Do validation of contentText and/or NSExtensionContext attachments here

    // get the object sharing

    NSExtensionItem * imageItem = [self.extensionContext.inputItems firstObject];

    if(!imageItem) {

        return NO;

    }

    // get content sharing

    NSItemProvider * imageItemProvider = [[imageItem attachments] firstObject];

    if(!imageItemProvider) {

        // get empty

        returnNO;

    }

    // determine whether the share url type public.textpublic.url

    if([imageItemProvider hasItemConformingToTypeIdentifier:@"public.url"]&&self.contentText) {

        return YES;

    } else {

        return NO;

    }

}

// sharing method

- (void)shareInfo {

    NSExtensionItem * infoItem = [self.extensionContext.inputItems firstObject];

    if(!infoItem) {

        return ;

    }

    // get content sharing

    NSItemProvider * infoItemProvider = [[infoItem attachments] firstObject];

    if(!infoItemProvider) {

        // get empty

        return ;

    }

    // determine whether the share url type public.textpublic.url

    if([infoItemProvider hasItemConformingToTypeIdentifier:@"public.url"]&&self.contentText) {

        if([infoItemProvider hasItemConformingToTypeIdentifier:(NSString*)kUTTypeURL]) {

            [infoItemProvider loadItemForTypeIdentifier:(NSString*)kUTTypeURL options:nil completionHandler:^(NSURL* infoUrl, NSError *error) {

                // After obtaining the information the information operations

            }];

        }

    }

}



Guess you like

Origin blog.csdn.net/sinat_30657013/article/details/62889849