WhatsApp的共享文本和图像没有在IOS
问题描述:
工作如果发送短信到WhatsApp的:WhatsApp的共享文本和图像没有在IOS
NSString *msg = @"Some Text";
NSString *urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
NSURL *whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
如果发送图片的WhatsApp:
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
UIImage* iconImage = [self captureScreen];// this will return a image
NSString* savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
_documentInteractionController.UTI = @"net.whatsapp.image";
_documentInteractionController.delegate = self;
[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
WhatsApp的是没有任何文本打开文本共享和图像也没有得到共享。请帮帮我。
答
您是否向您的plist添加了“LSApplicationQueriesSchemes”?
- 转到您的项目/支持文件/ YourProjectName-Info.plist XCode项目浏览器。
- 添加新的键值对。重点: LSApplicationQueriesSchemes类型:Array添加一个新的字符串项 “WhatsApp的”
请试试这个,让我知道,如果它仍然没有工作。
答
注: - 您只可以分享文字或图像,无论是在分享共同的WhatsApp没有从WhatsApp的侧工作
/*
//Share text
NSString *textToShare = @"Enter your text to be shared";
NSArray *objectsToShare = @[textToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
*/
//Share Image
UIImage * image = [UIImage imageNamed:@"images"];
NSArray *objectsToShare = @[image];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
http://*.com/questions/8354417/share-image-text-通过whatsapp-in-an-ios-app看看这个 – Sport 2014-11-24 12:52:52
我已经尝试过,但它不工作 – Praveen 2014-11-24 13:15:19
什么是错误 – Sport 2014-11-24 13:20:06