[英]how to integrate whatsapp in ios
hi now i am trying Integrate What's app in our app 您好,我现在尝试在我们的应用程序中集成什么应用程序
i have done already integrate Tweet 我已经完成整合推文
:-in this app i create two buttons one(chooseImagePressed) button is choose the image form local file and then and then second(tweetButtonPressed) this is post the image to Tweeter :-在此应用程序中,我创建两个按钮,第一个(chooseImagePressed)按钮选择图像形式的本地文件,然后第二个(tweetButtonPressed)将图像发布到Tweeter
- (IBAction)tweetButtonPressed:(id)sender
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"Look at this nice picture!"];
[tweetSheet addImage:self.imageView.image];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"please setup Twitter"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (IBAction)chooseImagePressed:(id)sender
{
self.pickerController = [[UIImagePickerController alloc] init];
self.pickerController.delegate = self;
self.pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.pickerController animated:YES completion:nil];
}
#pragma mark
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
{
self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
Please give me any idea about the how to integrated what's app into our app 请给我有关如何将什么应用程序集成到我们的应用程序中的任何想法
Please tell me this is possible or Not 请告诉我这可能与否
Thanks 谢谢
No , It's not possible as like tweeter and Facebook api
. 不 ,不可能
as like tweeter and Facebook api
。 But you can send message from your app to whatsapp if whatsapp is already installed as below 但是,如果已经按如下所示安装了whatsapp,则可以将消息从您的应用程序发送到whatsapp
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];//use this method stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding to convert it with escape char
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
But If you want to share document like files, images, video, you've to send it via UIDocumentInteractionController. 但是,如果您要共享文件,图像,视频之类的文档,则必须通过UIDocumentInteractionController发送。
Note: whatsapp should be installed for above two, otherwise you can't do anything as you like. 注意:应该为以上两个安装whatsapp,否则您将无法做任何事情。 See this for current whatsApp doc.
有关最新的whatsApp文档,请参见此内容。
Simple integration 简单整合
NSURL *whatsappURL = [NSURL URLWithString:@"https://api.whatsapp.com/send?phone=9530670491&text=hello"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
Swift 迅速
var whatsappURL = URL(string: "https://api.whatsapp.com/send?phone=9530670491&text=hello")
if UIApplication.shared.canOpenURL(whatsappURL) {
UIApplication.shared.openURL(whatsappURL!)
}
Also check this link https://www.whatsapp.com/faq/en/general/26000030 还要检查此链接https://www.whatsapp.com/faq/en/general/26000030
You will get more inputs here: 您将在此处获得更多输入:
http://www.whatsapp.com/faq/en/iphone/23559013 http://www.whatsapp.com/faq/zh-CN/iphone/23559013
-This is used to share any Image/vodeo with WhatsApp. -用于与WhatsApp共享任何图像/视频。 -You need to do UIDocumentInteractionController Class Reference in your code.
-您需要在代码中执行UIDocumentInteractionController类参考。 -You need to save the image to disk, and then create a UIDocumentInteractionController with that file URL.
-您需要将图像保存到磁盘,然后使用该文件URL创建一个UIDocumentInteractionController。 -Following are the code snaps for the same and you can share image with WhatsApp.
-以下是相同的代码捕捉,您可以与WhatsApp共享图像。
//Path of the image which is present in bundle
NSString* path = [[NSBundle mainBundle] pathForResource:@"images" ofType:@"jpg”];
/* here you can also give the path of image which is saved on disk.*/
if (path) {
NSURL* url = [NSURL fileURLWithPath:path];
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController presentPreviewAnimated:YES];
}
For text sharing 用于文本共享
//This is sharing text encoding with NSUTF8StringEncoding
NSString* strSharingText = [txtWhatsApp.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//This is whatsApp url working only when you having app in your Apple device
NSURL *whatsappURL = [NSURL URLWithString:[NSString stringWithFormat:@"whatsapp://send?text=%@",strSharingText]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
I prefer this documented method: 我更喜欢这种记录方法:
if let urlString = "https://wa.me/\(whatsappPhoneNumber)/?text=Hi. ".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: urlString),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
For Swift 4.2 and above
对于Swift 4.2及更高版本
let whatsAppURL = URL(string: "https://api.whatsapp.com/send?phone=0123456")
if UIApplication.shared.canOpenURL(whatsAppURL!)
{
UIApplication.shared.open(whatsAppURL!, options: [:], completionHandler: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.