在共享扩展程序中,我设法使用以下代码获取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吗?
答案 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