whatsapp、facebook、twitterなどのソーシャルアプリで件名やメッセージを共有しようとしていますが、コードの下は動作しません。ソーシャルアプリがユーザアプリケーションにインストールされていない場合は、AppStoreにリダイレクトする必要があります。親切に私のコードをチェックしてください。howsapp、facebook like swiftのようなソーシャルメディアアプリでデータを共有する方法
static func sendWhatspp(msg:String)
{
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 {
AFWrapper.showError("Error!", msg: "WhatsApp is not Installed")
}
}
}
}
static func sendTwitter(msg:String)
{
let urlWhats = "twitter://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 {
AFWrapper.showError("Error!", msg: "Twitter is not Installed")
}
}
}
}
static func sendFB(msg:String)
{
let urlWhats = "facebook://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 {
AFWrapper.showError("Error!", msg: "Facebook is not Installed")
}
}
}
}
static func sendAll(msg:String)
{
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 {
AFWrapper.showError("Error!", msg: "No Share app Installed")
}
}
}
}
「動作していません」と親切に定義しています –
TwitterとFacebookのURLは、 "sendWhatspp"という関数を呼び出すときに、 "whatsapp://" –
@MartinRで始まらないことを強く想定しています。それは私のiPhoneにインストールされている "WhatsAppがインストールされていません"というイベントになります。 –