使用UIActivityViewController将.vcf共享给WhatsApp失败,显示插件net.whatsapp.WhatsApp.ShareExtension失效错误
共享图像或文本正在使用UIActivityViewController工作,但共享.vcf不适用于whatsapp(适用于邮件/消息/信使等).
NSData *pVcfData = [CNContactVCardSerialization dataWithContacts:[NSArray arrayWithObject:pContact] error:&pError]; // creating contact data from CNContactVCardSerialization
NSURL *pFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:pFileNameWithAllowedCharacters]]; // wrote the data to file
NSError *pWriteError = nil;
if ([pVcfData writeToURL:pFileURL options:NSDataWritingAtomic error:&pWriteError])
{
NSArray *pActivityItems = @[pFileURL]; // passed the file URL as ActivityItem for UIActivityViewController
UIActivityViewController *pActivityVC = [[UIActivityViewController alloc] initWithActivityItems:pActivityItems applicationActivities:nil];
[pActivityVC setValue:pContactName forKey:@"subject"];
[self presentViewController:pActivityVC animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
除了.vcf之外,还有其他方法可以与whatsapp共享联系吗?请分享任何建议.
根据文档https://www.whatsapp.com/faq/en/iphone/23559013,将文件格式设置为 .wai 并将 UTI 设置为 net.whatsapp.image 只会在应用程序列表中显示 Whatsapp,
但它显示了其他应用程序,如添加到笔记,信使也与 whatsapp 选项一起。
if let imageData = UIImageJPEGRepresentation(image, 1.0)
{
let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDir: AnyObject = path[0]
let imagePath = documentsDir.stringByAppendingPathComponent("Main")
NSFileManager.defaultManager().createDirectoryAtPath(imagePath, withIntermediateDirectories: true, attributes: nil)
let tempFile = NSURL(fileURLWithPath: imagePath+"/image.wai")
do
{
try imageData.writeToURL(tempFile, options: .DataWritingAtomic)
self.documentController = UIDocumentInteractionController(URL: tempFile)
self.documentController.UTI = "net.whatsapp.image"
self.documentController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true)
}
catch
{
// alert
}
}
Run Code Online (Sandbox Code Playgroud)
请建议我是否在这里做错了什么