如何打开Facebook Messenger并直接指向某人? [英] How to open Facebook Messenger and direct to someone?
问题描述
我已经有FBSDK,可以使用FBSDKShareKit在Messenger上发送内容. 我只想与Facebook Messenger中的某人聊天.像这样:
I have FBSDK already and can use FBSDKShareKit send something on Messenger. I want just open a chat with someone in Facebook Messenger. like this:
-
单击我的应用程序中的按钮(示例:Facebook应用程序): http://i.imgur.com/j60P3Ng.png
Click a button in my app(sample: Facebook app): http://i.imgur.com/j60P3Ng.png
转到Facebook Messenger并与该人打开聊天: http://i.imgur.com/yU0EXKF.png
Go to Facebook Messenger and open a chat with this person: http://i.imgur.com/yU0EXKF.png
我该怎么办?
推荐答案
Swift 4
UI
在我的应用中,我将用户的Facebook ID显示为按钮:
Swift 4
UI
In my app I show a user's Facebook ID as a button:
@IBAction func messengerButton(_ sender: UIButton) {
if let id = sender.titleLabel?.text {
if let url = URL(string: "fb-messenger://user-thread/\(id)") {
// Attempt to open in Messenger App first
UIApplication.shared.open(url, options: [:], completionHandler: {
(success) in
if success == false {
// Messenger is not installed. Open in browser instead.
let url = URL(string: "https://m.me/\(id)")
if UIApplication.shared.canOpenURL(url!) {
UIApplication.shared.open(url!)
}
}
})
}
}
}
用户的Facebook ID
用户可以通过在Facebook上查找其他人的Facebook ID并观察URL来获取该人的ID:
User's Facebook ID
The user can get another person's Facebook ID from looking them up on Facebook and then observing the URL:
这篇关于如何打开Facebook Messenger并直接指向某人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!