我在这个应用程序中使用这些代码进行共享应用程序链接,但在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
将此代码实现到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()是一个显示警报的自定义函数.
将其添加到您的Info.plist
LSApplicationQueriesSchemes
将此代码实现到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()是一个显示警报的自定义函数.