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