Schemea 連結跳轉

let message: String! = "大家午安"
// 將訊息編碼成 UTF-8 格式
let encodeMessage = message.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
var schemeUrl : URL!
if sender == lineBtn {
    schemeUrl = URL(string: "line://msg/text/" + encodeMessage!)
}else if sender == fbBtn {
    schemeUrl = URL(string: "fb-messenger-api://share/?link=https://www.facebook.com")
}else if sender == igBtn {
    schemeUrl = URL(string: "instagram://camera")
}

if UIApplication.shared.canOpenURL(schemeUrl) {
    UIApplication.shared.open(schemeUrl!, options: [:], completionHandler: nil)
} else {
    // 若沒安裝 Line 則導到 App Store(id443904275 為 Line App 的 ID)
    let lineURL = URL(string: "itms-apps://itunes.apple.com/app/id443904275")!
    UIApplication.shared.open(lineURL, options: [:], completionHandler: nil)
}

Categorized in: