首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从iOS应用程序打开Facebook Messenger

从iOS应用程序打开Facebook Messenger
EN

Stack Overflow用户
提问于 2014-07-30 22:56:56
回答 2查看 11.1K关注 0票数 12

有人知道如何使用预填充文本打开Facebook messenger应用程序吗?

例如,要在指定用户打开messenger应用程序,您可以编写以下代码:

代码语言:javascript
复制
 NSURL *fbURL = [NSURL URLWithString:@"fb-messenger://user-thread/USER_ID"]; 
if ([[UIApplication sharedApplication] canOpenURL: fbURL]) {
    [[UIApplication sharedApplication] openURL: fbURL];
}

对于What应用程序来说非常简单:

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

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-30 22:59:55

有这样一个函数,但它只存在于Facebook的SDK中。

看看这个-- https://developers.facebook.com/docs/ios/share#message-dialog

票数 5
EN

Stack Overflow用户

发布于 2019-10-02 16:21:02

Swift 4和5

代码语言:javascript
复制
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!)
                }
            }
        })
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25040110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档