当前位置:  开发笔记 > 编程语言 > 正文

使用whatsapp分享链接

如何解决《使用whatsapp分享链接》经验,为你挑选了1个好方法。

我在这个应用程序中使用这些代码进行共享应用程序链接,但在whatsapp的文本字段中没有任何内容.如果使用简单的文本然后它的工作.任何人都可以提出最终结果.

NSString *theTempMessage = @"whatsapp://send?text=https://itunes.apple.com/in/app/myapp/id1054375332?ls=1&mt=8";
NSString *theFinalMessage;

theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"];
theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"," withString:@"%2C"];
theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
theFinalMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];

NSString * stringToSend=theFinalMessage;
NSURL *whatsappURL = [NSURL URLWithString:stringToSend];

if ([[UIApplication sharedApplication] canOpenURL: whatsappURL])

{
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

Ankit Kumar .. 9

将其添加到您的Info.plist

LSApplicationQueriesSchemes
    
        whatsapp
    

将此代码实现到ViewController,您需要打开WhatsApp进行共享.(例如说按钮动作)swift 3版本的更新(Xcode 8.x):更新了弃用:

var str = "This is the string which you want to share to WhatsApp"
str=str.addingPercentEncoding(withAllowedCharacters: (NSCharacterSet.urlQueryAllowed))!
let whatsappURL = URL(string: "whatsapp://send?text=\(str)")
if UIApplication.shared.canOpenURL(whatsappURL) {
   UIApplication.shared.open(whatsappURL!, options: [:], completionHandler: nil)
} else {
   showAlert(message: "Whatsapp is not installed on this device. Please install Whatsapp and try again.")
}

这里showAlert()是一个显示警报的自定义函数.



1> Ankit Kumar ..:

将其添加到您的Info.plist

LSApplicationQueriesSchemes
    
        whatsapp
    

将此代码实现到ViewController,您需要打开WhatsApp进行共享.(例如说按钮动作)swift 3版本的更新(Xcode 8.x):更新了弃用:

var str = "This is the string which you want to share to WhatsApp"
str=str.addingPercentEncoding(withAllowedCharacters: (NSCharacterSet.urlQueryAllowed))!
let whatsappURL = URL(string: "whatsapp://send?text=\(str)")
if UIApplication.shared.canOpenURL(whatsappURL) {
   UIApplication.shared.open(whatsappURL!, options: [:], completionHandler: nil)
} else {
   showAlert(message: "Whatsapp is not installed on this device. Please install Whatsapp and try again.")
}

这里showAlert()是一个显示警报的自定义函数.


由于在iOS 10中不推荐使用`openURL`你需要使用`openURL`:`UIApplication.shared.open(whatsappURL!,options:[:],completionHandler:nil)`
推荐阅读
mobiledu2402852357
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有