Hello i want to open the eMail program from my App and the body should already be defined. I can open the eMail but don't know how to define the body of the eMail as a given Parameter to show a given standard text. Anyone can help? Heres the code i use to open Email:
//EMAIL
let email = "foo#bar.com"
let urlEMail = NSURL(string: "mailto:\(email)")
if UIApplication.sharedApplication().canOpenURL(urlEMail!) {
UIApplication.sharedApplication().openURL(urlEMail!)
} else {
print("Ups")
}
If you'd like to open the built-in email app as opposed to showing the MFMailComposeViewController as has been mentioned by others, you could construct a mailto: link like this:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=\(subject)&body=\(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:foo#bar.com?\(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
Just to save anyone typing, for 2016 the syntax has changed slightly:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah#blah.com?subject=\(subject)&body=\(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
Swift 3 Version
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah#blah.com?subject=\(subject)&body=\(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL: NSURL = NSURL(string: coded!) {
if UIApplication.shared.canOpenURL(emailURL as URL) {
UIApplication.shared.openURL(emailURL as URL)
}
}
You can do it using MFMailComposeViewController:
import MessageUI
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email#email.com"])
mailComposerVC.setSubject("Subject")
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)
Also, you need to implement mailComposeController:didFinishWithResult:error: from MFMailComposeViewControllerDelegate where you should dismiss MFMailComposeViewController
Swift 4.0
let email = "feedback#company.com"
let subject = "subject"
let bodyText = "Please provide information that will help us to serve you better"
if MFMailComposeViewController.canSendMail() {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(bodyText, isHTML: true)
self.present(mailComposerVC, animated: true, completion: nil)
} else {
let coded = "mailto:\(email)?subject=\(subject)&body=\(bodyText)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL = URL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL)
{
UIApplication.shared.open(emailURL, options: [:], completionHandler: { (result) in
if !result {
// show some Toast or error alert
//("Your device is not currently configured to send mail.")
}
})
}
}
}
Use the MFMailComposeViewController like this:
Import the MessageUI
import MessageUI
Add the delegate to your class:
class myClass: UIViewController, MFMailComposeViewControllerDelegate {}
Configure the email preset you want to have
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
mail.setMessageBody("Body", isHTML: true)
mail.setToRecipients(["my#email.com"])
presentViewController(mail, animated: true, completion: nil)
Put this method in your code:
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
dismissViewControllerAnimated(true, completion: nil)
}
There you go, works now.
Similar to url construction in the other answers, but instead of calling addingPercentEncoding you can use URLComponents:
var components = URLComponents(string: "youremail#test.com")
components?.queryItems = [URLQueryItem(name: "subject", value: "Your Subject")]
if let mailUrl = components?.url {
UIApplication.shared.open(mailUrl, options: [:], completionHandler: nil)
}
Updated for Xcode 12.5
let url = NSURL(string: "mailto:mailto:someone#example.com")
UIApplication.shared.open(url! as URL)
or if you would like to add an embedded subject
let url = NSURL(string: "mailto:someone#example.com?subject=This%20is%20the%20subject&cc=someone_else#example.com&body=This%20is%20the%20body")
or if you want to add multiple email addresses
let url = NSURL(string: "mailto:mailto:someone#example.com,someoneelse#example.com")
UIApplication.shared.open(url! as URL)
I suggest to use Apple's way, which you can find in official documentation about MFMailComposeViewController. It opens a modal view controller with the email, which is dismissed after sending. Thus user stays in your app.
Swift 5 version of #mclaughj answer
let email = "foo#bar.com"
let subject = "Your Subject"
let body = "Plenty of email body."
let coded = "mailto:\(email)?subject=\(subject)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL as URL){
UIApplication.shared.open(emailURL as URL)
}
}
Cheers!
Related
I am integrating sharing options from my app to Snapchat.
I have a dynamic URL obtained in an object and clicking the Snapchat's share button directly opens the app if Snapchat is there on the device and show the text with the link. I am using the below code to share which gives an error on Snapchat. Below is my Code.
func shareTextOnSnapchat(obj:VideoData) {
let shaUrl = URL(string: obj.share_url ?? "")
if let myURL:URL = shaUrl{
let promoText = "Check out this great new video from \(obj.name ?? ""), I found on talent app"
let shareString = "snapchat://text=\(promoText)&url=\(myURL)"
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
let url = URL(string: escapedShareString)
UIApplication.shared.openURL(url!)
}
}
I have used this to post video to snapchat. You have option to either post text or a video.
Pod used
pod 'SnapSDK', :subspecs => ['SCSDKCreativeKit']
import SCSDKCreativeKit
var scInstalled = false
override func viewDidLoad() {
super.viewDidLoad()
scInstalled = schemeAvailable(scheme: "snapchat://")
}
func ShowSnapchat(){
if scInstalled {
//shareTextOnSnapchat(obj:videoObj ?? VideoData())
shareFileOnSnapchat(obj:videoObj ?? VideoData())
}else{
downloadSharingAppAlert(appName:"Snapchat")
}
}
func shareTextOnSnapchat(obj:VideoData) {
let shaUrl = URL(string: obj.share_url ?? "")
if let myURL:URL = shaUrl{
let originalString = "\(myURL)"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)
//let url = URL(string: "snapchat://snap?text=\(escapedString!)")
let url = URL(string: "https://www.snapchat.com/send?text=\(escapedString!)")
if UIApplication.shared.canOpenURL(url! as URL)
{
UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
}
}
}
func shareFileOnSnapchat(obj:VideoData){
//// SHARE VIDEO
LoadingOverlay.shared.showLoaderView(view: self.view)
let shaUrl = URL(string: obj.output_vid ?? "")
if let myURL:URL = shaUrl{
let snapVideo = SCSDKSnapVideo(videoUrl: myURL)
let snapContent = SCSDKVideoSnapContent(snapVideo: snapVideo)
// Send it over to Snapchat
snapAPI.startSending(snapContent) { (error) in
if let error = error {
print(error.localizedDescription)
LoadingOverlay.shared.hideLoaderView()
MyCustomAlert.sharedInstance.ShowAlert(vc: self, myTitle: "", myMessage: StringClass.sharedInstance.lcStr_oopsSomethingWentwrong)
} else {
// success
print("Posted to snapchat")
LoadingOverlay.shared.hideLoaderView()
MyCustomAlert.sharedInstance.ShowAlert(vc: self, myTitle: "", myMessage: StringClass.sharedInstance.lcStr_postedToSnapchat)
}
}
}
}
}
func downloadSharingAppAlert(appName:String){
var appStoreURL = "https://apps.apple.com/in/app/snapchat/id447188370"
//Open Appstore for Download
}
I'm trying to build an application where I can share an address and open that in any navigation app (Google maps, Apple maps, waze,...).
Below is the code that I currently have (after going through pages of google search results including dozens of stackoverflow questions)
#IBAction func navigeer(_ sender: Any) {
var items = [AnyObject]()
let latitude: Double = 52.033809
let longitude: Double = 6.882286
let locationTitle = "Navigate to this address"
let URLString = "https://maps.apple.com?ll=\(latitude),\(longitude)"
guard let cachesPathString = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first else {
print("Error: couldn't find the caches directory.")
return
}
if let url = NSURL(string: URLString) {
items.append(url)
}
let vCardString = [
"BEGIN:VCARD",
"VERSION:3.0",
"N:;Shared Location;;;",
"FN:Shared Location",
"item1.URL;type=pref:http://maps.apple.com/?ll=\(latitude),\(longitude)",
"item1.X-ABLabel:map url",
"END:VCARD"
].joined(separator: "\n")
let vCardFilePath = (cachesPathString as NSString).appendingPathComponent("vCard.loc.vcf")
let nsVCardData = NSURL(fileURLWithPath: vCardFilePath)
let shareItems:Array = [nsVCardData]
let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
present(activityController, animated:true, completion: nil)
}
When I run the application on my simulator I get the following:
After clicking the share button
Why don't I get app suggestions like Apple maps or Google maps? I also don't get why it suggests me to copy it to contacts..
Thanks in advance.
To share location using UIActivityViewController, Swift 5
func activityItems(latitude: Double, longitude: Double) -> [AnyObject]? {
var items = [AnyObject]()
let URLString = "https://maps.apple.com?ll=\(latitude),\(longitude)"
if let url = NSURL(string: URLString) {
items.append(url)
}
let locationVCardString = [
"BEGIN:VCARD",
"VERSION:3.0",
"PRODID:-//Joseph Duffy//Blog Post Example//EN",
"N:;Shared Location;;;",
"FN:Shared Location",
"item1.URL;type=pref:\(URLString)",
"item1.X-ABLabel:map url",
"END:VCARD"
].joined(separator: "\n")
guard let vCardData : NSSecureCoding = locationVCardString.data(using: .utf8) as NSSecureCoding? else {
return nil
}
let vCardActivity = NSItemProvider(item: vCardData, typeIdentifier: kUTTypeVCard as String)
items.append(vCardActivity)
return items
}
How to use?
if let shareObject = self.activityItems(latitude: 52.033809, longitude: 6.882286) {
//open UIActivityViewController
}
Reference Link : https://new.josephduffy.co.uk/posts/ios-share-sheets-the-proper-way-locations
Try this..
// if the device has google maps installed in it
if (UIApplication.shared.canOpenURL(NSURL(string:"comgooglemaps://")! as URL)) {
UIApplication.shared.openURL(NSURL(string:
"comgooglemaps://?saddr=&daddr=\(myLatitude),\(myLongitude)&directionsmode=driving")! as URL)
}
// if google maps is not installed, try apple map
else if (UIApplication.shared.canOpenURL(NSURL(string:"http://maps.apple.com/maps")! as URL)) {
// apple map
let url = "http://maps.apple.com/maps?saddr=\(from.latitude),\(from.longitude)&daddr=\(to.latitude),\(to.longitude)"
UIApplication.shared.openURL(URL(string:url)!)
}
// if apple map is also not there, it will show an appStore link to download apple map application.
So this's my code for app invite :
private func inviteFriends() {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "...")
content.appInvitePreviewImageURL = URL(string: "...")
FBSDKAppInviteDialog.show(from: self, with: content, delegate: nil)
}
This code works fine but if I try to add the promotional code like this :
private func inviteFriends() {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "...")
content.appInvitePreviewImageURL = URL(string: "...")
content.promotionCode = "preview"
content.promotionText = "Use the *preview* code to unlock the app"
FBSDKAppInviteDialog.show(from: self, with: content, delegate: nil)
}
The the invite VC is not shown any more (the function is called but nothing is showing). What did I missed here ?
The issue was that I've used special character like * so removing it make the app works fine my final code is like this :
private func inviteFriends() {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "...")
content.appInvitePreviewImageURL = URL(string: "...")
content.promotionCode = "preview"
content.promotionText = "Use the preview code to unlock the app"
FBSDKAppInviteDialog.show(from: self, with: content, delegate: nil)
}
I have an iOS Xcode 7 Swift 2 project I'm working on. The app posts photos to Facebook and Twitter using:
var shareToFacebook: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
and
var shareToTwitter: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
Love how easy and simple for just posting a photo to these two social medias. I didn't need or want the APIs for them.
I want to do something similar and simple for Instagram. What is the best way to do this without having to deal with Instagram API? Or do I have no choice?
My photo data is saved using NSCoding, not in the DocumentDirectory. I looked here for integration but this is for a photo saved in the app directory.
Just something simple like what I already have for Facebook and Twitter.
Updated for Swift 3
import UIKit
import Foundation
class InstagramManager: NSObject, UIDocumentInteractionControllerDelegate {
private let kInstagramURL = "instagram://app"
private let kUTI = "com.instagram.exclusivegram"
private let kfileNameExtension = "instagram.igo"
private let kAlertViewTitle = "Error"
private let kAlertViewMessage = "Please install the Instagram application"
var documentInteractionController = UIDocumentInteractionController()
// singleton manager
class var sharedManager: InstagramManager {
struct Singleton {
static let instance = InstagramManager()
}
return Singleton.instance
}
func postImageToInstagramWithCaption(imageInstagram: UIImage, instagramCaption: String, view: UIView) {
// called to post image with caption to the instagram application
let instagramURL = NSURL(string: kInstagramURL)
if UIApplication.shared.canOpenURL(instagramURL! as URL) {
let jpgPath = (NSTemporaryDirectory() as NSString).appendingPathComponent(kfileNameExtension)
do {
try UIImageJPEGRepresentation(imageInstagram, 1.0)?.write(to: URL(fileURLWithPath: jpgPath), options: .atomic)
} catch {
print(error)
}
let rect = CGRect(x: 0, y: 0, width: 612, height: 612)
let fileURL = NSURL.fileURL(withPath: jpgPath)
documentInteractionController.url = fileURL
documentInteractionController.delegate = self
documentInteractionController.uti = kUTI
// adding caption for the image
documentInteractionController.annotation = ["InstagramCaption": instagramCaption]
documentInteractionController.presentOpenInMenu(from: rect, in: view, animated: true)
} else {
/// display some message about how it didn't work
/// Like: UIAlertController(title: kAlertViewTitle, message: kAlertViewMessage, preferredStyle: .alert)
}
}
}
and then in the ViewController you want to call it in...
InstagramManager.sharedManager.postImageToInstagramWithCaption(imageInstagram: <YOUR IMAGE>, instagramCaption: shareText, view: self.view)
This opens the 'open-in' function if Instagram is installed
I looked here and found a solution:
I created an NSObject:
import UIKit
import Foundation
class InstagramManager: NSObject, UIDocumentInteractionControllerDelegate {
private let kInstagramURL = "instagram://app"
private let kUTI = "com.instagram.exclusivegram"
private let kfileNameExtension = "instagram.igo"
private let kAlertViewTitle = "Error"
private let kAlertViewMessage = "Please install the Instagram application"
var documentInteractionController = UIDocumentInteractionController()
// singleton manager
class var sharedManager: InstagramManager {
struct Singleton {
static let instance = InstagramManager()
}
return Singleton.instance
}
func postImageToInstagramWithCaption(imageInstagram: UIImage, instagramCaption: String, view: UIView) {
// called to post image with caption to the instagram application
let instagramURL = NSURL(string: kInstagramURL)
if UIApplication.sharedApplication().canOpenURL(instagramURL!) {
let jpgPath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent(kfileNameExtension)
UIImageJPEGRepresentation(imageInstagram, 1.0)!.writeToFile(jpgPath, atomically: true)
let rect = CGRectMake(0,0,612,612)
let fileURL = NSURL.fileURLWithPath(jpgPath)
documentInteractionController.URL = fileURL
documentInteractionController.delegate = self
documentInteractionController.UTI = kUTI
// adding caption for the image
documentInteractionController.annotation = ["InstagramCaption": instagramCaption]
documentInteractionController.presentOpenInMenuFromRect(rect, inView: view, animated: true)
} else {
// alert displayed when the instagram application is not available in the device
UIAlertView(title: kAlertViewTitle, message: kAlertViewMessage, delegate:nil, cancelButtonTitle:"Ok").show()
}
}
}
Then in my #IBAction I used:
let image = self.photoImageView.image
InstagramManager.sharedManager.postImageToInstagramWithCaption(image!, instagramCaption: "\(self.description)", view: self.view)
This opens bring a menu up with the 'open-in' style and the user can open the app in Instagram (if installed).
Here is a reusable class with swift 4+. Working in Xcode 10.1.
Make swift empty file.
copy and paste the below code into the file.
import UIKit
import Foundation
class InstagramHelper: NSObject, UIDocumentInteractionControllerDelegate {
private let kInstagramURL = "instagram://den3079"
private let kUTI = "com.instagram.exclusivegram"
private let kfileNameExtension = "instagram.igo"
private let kAlertViewTitle = "Error"
private let kAlertViewMessage = "Please install the Instagram application"
var documentInteractionController = UIDocumentInteractionController()
// singleton manager
class var sharedManager: InstagramHelper {
struct Singleton {
static let instance = InstagramHelper()
}
return Singleton.instance
}
func postImageToInstagramWithCaption(imageInstagram: UIImage, instagramCaption: String, controller: UIViewController) {
// called to post image with caption to the instagram application
let instagramURL = URL(string: kInstagramURL)
DispatchQueue.main.async {
if UIApplication.shared.canOpenURL(instagramURL!) {
let jpgPath = (NSTemporaryDirectory() as NSString).appendingPathComponent(self.kfileNameExtension)
if let jpegData = UIImageJPEGRepresentation(imageInstagram, 1.0) {
do {
try jpegData.write(to: URL(fileURLWithPath: jpgPath), options: .atomicWrite)
} catch {
print("write image failed")
}
}else {
let jpegData = UIImagePNGRepresentation(imageInstagram)
do {
try jpegData?.write(to: URL(fileURLWithPath: jpgPath), options: .atomicWrite)
} catch {
print("write image failed")
}
}
let fileURL = NSURL.fileURL(withPath: jpgPath)
self.documentInteractionController.url = fileURL
self.documentInteractionController.delegate = self
self.documentInteractionController.uti = self.kUTI
// adding caption for the image
self.documentInteractionController.annotation = ["InstagramCaption": instagramCaption]
self.documentInteractionController.presentOpenInMenu(from: controller.view.frame, in: controller.view, animated: true)
} else {
// alert displayed when the instagram application is not available in the device
self.showAlert("", message: self.kAlertViewMessage, controller: controller)
}
}
}
func showAlert(_ title: String, message: String, controller : UIViewController){
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { action -> Void in
//Just dismiss the action sheet
let selector: Selector = NSSelectorFromString("alertOkButtonHandler")
if controller.responds(to: selector){
_ = controller.perform(selector)
}
})
alert.addAction(okAction)
controller.present(alert, animated: true, completion: nil)
}}
And use of this function in ViewController class.
InstagramHelper.sharedManager.postImageToInstagramWithCaption(imageInstagram: img!, instagramCaption: "www.google.com", controller: self)
For one of my app, I wanted to share data to WhatsApp contacts. I tried few solutions overs the StackOverflow but couldn't get exact solution. After some trials could achieve what I was looking for, so sharing here for anyone's future reference.
var url = NSURL(string: "whatsapp://send?text=Hello%20Friends%2C%20Sharing%20some%20data%20here...%20!")
//Text which will be shared on WhatsApp is: "Hello Friends, Sharing some data here... !"
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().open(url as URL, options: [:]) { (success) in
if success {
print("WhatsApp accessed successfully")
} else {
print("Error accessing WhatsApp")
}
}
}
Note: text needs to be URL encoded. You can get it using any of the open source tools over internet or using addingPercentEncoding(withAllowedCharacters:) function in iOS.
e.g.
var urlString = "Hello Friends, Sharing some data here... !"
var urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
var url = NSURL(string: "whatsapp://send?text=\(urlStringEncoded!)")
Swift 5
Code
let urlWhats = "whatsapp://send?text=\("Hello World")"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
UIApplication.shared.open(whatsappURL as URL)
}
else {
print("please install watsapp")
}
}
}
Swift 3.0
Try with this code for access watsapp in your application. Its working perfectly for me.
#IBAction func sendButtonAction(_ sender: Any)
{
let date = Date()
let msg = "Hi my dear friends\(date)"
let urlWhats = "whatsapp://send?text=\(msg)"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
UIApplication.shared.openURL(whatsappURL as URL)
} else {
print("please install watsapp")
}
}
}
}
Addition to above solutions, starting from iOS 9, we need to add whatsapp to LSApplicationQueriesSchemes key in info.plist. After this only it worked for me.
My code is Looking Like this
let encodeQuizStr = "Check Out The Quiz With link \n http://www.proprofs.com "
let urlQuizStringEncoded = encodeQuizStr.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
guard let whatsAppUrl = NSURL(string: "whatsapp://send?text="+urlQuizStringEncoded!) else { return }
if UIApplication.shared.canOpenURL(whatsAppUrl as URL) {
if #available(iOS 10.0, *) {
print(urlQuizStringEncoded!)
UIApplication.shared.open(whatsAppUrl as URL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(whatsAppUrl as URL)
}
}
else{
ProjectUtility.AlertWith(self, message: " What's App is Not Available.", Title: "Sorry")
}
working fine But When I put This URL
("http://www.proprofs.com/quiz-school/story.php?title=pq-find-out-which-ice-age-character-you-are ")
Then Its Not Working Please Check Thanks.HelpWill Be Appriciated.
Swift 5
Please follow the below steps for sharing on WhatsApp through URL Schemes
Add this code in your app "info.plist"
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
For sharing text and URL
Code
#IBAction func whatsappShareText(_ sender: AnyObject) {
let message = "First Whatsapp Share & https://www.google.co.in"
var queryCharSet = NSCharacterSet.urlQueryAllowed
// if your text message contains special characters like **+ and &** then add this line
queryCharSet.remove(charactersIn: "+&")
if let escapedString = message.addingPercentEncoding(withAllowedCharacters: queryCharSet) {
if let whatsappURL = URL(string: "whatsapp://send?text=\(escapedString)") {
if UIApplication.shared.canOpenURL(whatsappURL) {
UIApplication.shared.open(whatsappURL, options: [: ], completionHandler: nil)
} else {
debugPrint("please install WhatsApp")
}
}
}
}
Happy Coding!
As per their FAQ, you should be using the universal links instead:
https://wa.me/1234567890
Reference: https://faq.whatsapp.com/563219570998715/?locale=en_US