在共享扩展中,我设法使用以下代码获取了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
关于ios - 从Safari分享扩展中获取HTML?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31919684/