从iOS应用程序中打开Facebook Messenger

12

有人知道如何打开预先填好文本的Facebook Messenger应用程序吗?

例如,要在指定用户处打开Messenger应用程序,可以编写以下内容:

 NSURL *fbURL = [NSURL URLWithString:@"fb-messenger://user-thread/USER_ID"]; 
if ([[UIApplication sharedApplication] canOpenURL: fbURL]) {
    [[UIApplication sharedApplication] openURL: fbURL];
}

使用 Whatsapp 非常简单:

NSURL *whatsappURL = [NSURL URLWithString:[NSString stringWithFormat:@"whatsapp://send?text=%@", @"String to post here"]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

你好,能告诉我你是如何实现的吗?我遇到了类似的问题。 - user3575114
2个回答

5

你好,请问你能告诉我它是哪一个吗?我已经找了几个小时,没有找到任何与消息相关的内容。 - Denisa Toderean
@DenisaToderean,请查看更新答案中的链接。这是目前FB iOS SDK版本中最接近的解决方案。 - Sergey Grischyov
https://developers.facebook.com/docs/ios/share 我认为这就是它,消息对话框 :) - Denisa Toderean
谢谢!这就是它 :) - Denisa Toderean
2
@DenisaToderean 不客气!如果有帮助的话,请别忘记将答案标记为已接受并点赞!祝编码愉快;-) - Sergey Grischyov

2

Swift 4 & 5

private func inviteViaFacebook() {
    let id = "akbarkhanshinwar"
    // If you have User id the use this URL
    let urlWithId = "fb-messenger://user-thread/\(id)"
    // If you don't have User id then use this URL
    let urlWithoutId = "fb-messenger://user-thread"
    if let url = URL(string: urlWithId) {

        // this will open your Messenger App
        UIApplication.shared.open(url, options: [:], completionHandler: {
            (success) in

            if success == false {
                // If Messenger App is not installed then it will open browser.
                // If you have User id the use this URL
                let urlWithIdForBrowser = "https://m.me/\(id)"
                // If you don't have User id then use this URL
                let urlWithoutIdForBrowser = "https://m.me"
                let url = URL(string: urlWithIdForBrowser)
                if UIApplication.shared.canOpenURL(url!) {
                    UIApplication.shared.open(url!)
                }
            }
        })
    }
}

这太棒了。 - hbtpoprock

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接