从 Safari 共享扩展获取 HTML?
Get HTML from Safari 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 吗?
检查以下代码,
[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
在分享扩展中,我通过以下代码成功获取了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 吗?
检查以下代码,
[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