如何从我的应用程序发送文本到特定的WhatsApp用户?

时间:2015-08-24 03:06:21

标签: ios whatsapp

我想从我的应用中向特定的WhatsApp用户发送短信(例如“Hello World”)。

基于此whatsapp FAQ link,我可以使用自定义网址方案使用预定义文本向特定联系人号码启动whatsapp:

问题:

1)但是从哪里获取联系人ID,abid?:

2)我如何知道联系电话号码首先是否有whatsapp [对于iOS我们因为沙箱限制而无法访问它?]?

3)如何将联系人ID插入网址:

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];

if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

1 个答案:

答案 0 :(得分:-2)

您可以改为UIactivityViewController,因此会显示支持您文字的应用:

NSString * text = @"Hello World!!";
NSArray * itemsArray = @[text];
NSArray * applicationActivities = nil;

UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];

activityViewController.excludedActivityTypes = @[
                                                 UIActivityTypePostToWeibo,
                                                 UIActivityTypeAssignToContact,
                                                 UIActivityTypeAirDrop,
                                                 UIActivityTypeAddToReadingList,
                                                 // Whatever you want prevent to appear...
                                                 ];

activityViewController.popoverPresentationController.sourceView = self.view;

[self presentViewController:activityViewController animated:YES completion:nil];

您还可以添加图片等。