【问题标题】:how to integrate whatsapp in ios如何在ios中集成whatsapp
【发布时间】:2014-04-25 12:57:57
【问题描述】:

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

我已经整合了 Tweet

:-在这个应用程序中我创建了两个按钮 one(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];
}

请告诉我如何将什么应用程序集成到我们的应用程序中

请告诉我这是否可能

谢谢

【问题讨论】:

  • 不,这是不可能的,whatsapp 没有任何您可以使用的公共 API。
  • @iPatel 感谢回复在模拟器中安装什么应用程序是可能的或不是

标签: ios iphone objective-c whatsapp


【解决方案1】:

我更喜欢这种documented 方法:

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

【讨论】:

    【解决方案2】:

    适用于 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)
    }
    

    【讨论】:

      【解决方案3】:

      简单的集成

         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

      【讨论】:

      • 如果未安装 whatsapp,它将启动 safari。有什么方法可以检查是否安装了whatsapp?如果没有,将用户重定向到应用商店。
      【解决方案4】:

      ,不可能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,否则不能为所欲为。 See this for current whatsApp doc.

      【讨论】:

      • 感谢重播 模拟器中的应用安装是否可行
      • @Vasavi 不。模拟器不可能。
      • @Mani 现在我没有 iphone
      • @Vasavi 查看 iPatel 评论,它可能会对您有所帮助。
      【解决方案5】:

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

      http://www.whatsapp.com/faq/en/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];
          }
      

      【讨论】:

        猜你喜欢
        • 2017-02-23
        • 2018-02-08
        • 1970-01-01
        • 1970-01-01
        • 2017-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多