繁体   English   中英

如何在iOS中集成whatsapp

[英]how to integrate whatsapp in ios

您好,我现在尝试在我们的应用程序中集成什么应用程序

我已经完成整合推文

:-在此应用程序中,我创建两个按钮,第一个(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];
}

请给我有关如何将什么应用程序集成到我们的应用程序中的任何想法

请告诉我这可能与否

谢谢

,不可能as like tweeter and Facebook api 但是,如果已经按如下所示安装了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];
}

但是,如果您要共享文件,图像,视频之类的文档,则必须通过UIDocumentInteractionController发送

注意:应该为以上两个安装whatsapp,否则您将无法做任何事情。 有关最新的whatsApp文档,请参见此内容。

简单整合

   NSURL *whatsappURL = [NSURL URLWithString:@"https://api.whatsapp.com/send?phone=9530670491&text=hello"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

迅速

var whatsappURL = URL(string: "https://api.whatsapp.com/send?phone=9530670491&text=hello")
if UIApplication.shared.canOpenURL(whatsappURL) {
UIApplication.shared.openURL(whatsappURL!)
}

还要检查此链接https://www.whatsapp.com/faq/en/general/26000030

您将在此处获得更多输入:

http://www.whatsapp.com/faq/zh-CN/iphone/23559013

-用于与WhatsApp共享任何图像/视频。 -您需要在代码中执行UIDocumentInteractionController类参考。 -您需要将图像保存到磁盘,然后使用该文件URL创建一个UIDocumentInteractionController。 -以下是相同的代码捕捉,您可以与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];
        }

用于文本共享

 //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];
    }

我更喜欢这种记录方法:

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)
}

对于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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM