简体   繁体   中英

Get HTML from Safari share extension?

In the share extension, I managed to get the URL of the Safari page with the following code:

NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
NSItemProvider *itemProvider = item.attachments.firstObject;
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]){
    [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL
                                    options:nil
                          completionHandler:^(NSURL *url, NSError *error){
                              NSLog(@"%@", url.absoluteString);
                          }];
}

Can I get also the HTML of the page?

Check the following code,

[itemProvider loadItemForTypeIdentifier: (NSString *) kUTTypePropertyList
                                options: 0
                      completionHandler: ^(id<NSSecureCoding> item, NSError *error) {
                          if (item != nil) {
                              NSDictionary *resultDict = (NSDictionary *) item;
                              NSString *jsString = resultDict[NSExtensionJavaScriptPreprocessingResultsKey][@"content"];
                          }
                      }];

Creating an iOS App Extension to perform custom actions with Safari content - swiftiostutorials.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM