簡體   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