从Safari共享扩展获取HTML?

时间:2015-08-10 12:33:06

标签: ios xcode safari-extension ios8-extension ios8-share-extension

在共享扩展程序中,我设法使用以下代码获取Safari页面的URL:

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);
                          }];
}

我还能获得该页面的HTML吗?

1 个答案:

答案 0 :(得分:4)

检查以下代码,

[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