I am trying to implement share extension for my app. Its working good in safari browser and youtube app (i.e) when i share from these apps i get the public.url which is the url to be shared.
When i tried the same in chrome it was not showing the extension. When i added the NSExtensionActivationSupportsText under the NSExtensionActivationRule to true its started showing. But when i try to share the contents i am unable to fetch the URL String which is to be shared. I get only contentText.
I have followed the approach shown in this link https://stackoverflow.com/a/31942744/6199038.
I have also added the demoProcessor.js
var MyPreprocessor = function() {};
MyPreprocessor.prototype = {
run: function(arguments) {
arguments.completionFunction({"URL": document.URL, "pageSource": document.documentElement.outerHTML, "title": document.title, "selection": window.getSelection().toString()});
}
};
var ExtensionPreprocessingJS = new MyPreprocessor;
I am using SLComposeServiceViewController
In my ShareViewController.m i am trying to get the data as shown below,
for safari i used this which is working fine
NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
NSItemProvider *itemProvider = [[item.userInfo valueForKey:NSExtensionItemAttachmentsKey] objectAtIndex:0];
if ([itemProvider hasItemConformingToTypeIdentifier:@"public.url"]) {
[itemProvider loadItemForTypeIdentifier:@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
urlString = url.absoluteString;
NSLog(@"urlString %@",urlString);
}];
}
Then i modified my code to this to get the URL from chrome, Which is not working.
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypePropertyList]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypePropertyList options:nil completionHandler:^(NSDictionary *jsDict, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *jsPreprocessingResults = jsDict[NSExtensionJavaScriptPreprocessingResultsKey];
NSString *selectedText = jsPreprocessingResults[@"selection"];
NSString *pageTitle = jsPreprocessingResults[@"title"];
NSString *URL = jsPreprocessingResults[@"URL"];
NSLog(@"selectedText %@",selectedText);
NSLog(@"pageTitle %@",pageTitle);
NSLog(@"URL %@",URL);
});
}];
break;
}
}
}
PLEASE ADVICE