我试图在fb messenger上发送包含网址的短信给我的朋友,但没有办法发送它们。
我试过这个
let result = FBSDKMessengerSharer.messengerPlatformCapabilities().rawValue & FBSDKMessengerPlatformCapability.Image.rawValue
if result != 0 {
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: Urls().WEONE_ITUNES_TINYURL)
content.contentDescription = "Dscription"
content.contentTitle = "Title"
let facebookSendButton: FBSDKSendButton = FBSDKSendButton()
facebookSendButton.shareContent = content
facebookSendButton.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
} else {
Utils().alertView(self, title: "Cannot Send Message", message: "Your device is not able to send Facebook Messenger messages.")
}
但这仅用于分享链接
我尝试使用urlscheme发送消息,但它只是打开了fb messenger:
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb-messenger-api://")!) {
var msgString = "Hello World: https://randomurl.com"
let urlStringEncoded = msgString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
var urlString = "fb-messenger://messaging?text=\(urlStringEncoded!)"
UIApplication.sharedApplication().openURL(NSURL(string: urlString)!)
}
else {
print("Failed to open fb-messenger App ")
}
在Android中,这可能是
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Your message");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.show(this, "Please Install Facebook Messenger");
}
这是从android
发送的任何帮助将不胜感激
提前致谢
答案 0 :(得分:2)
与Swift中的ВикторИванов答案相同:
let content = FBSDKShareLinkContent()
content.quote = "A nice quote here..."
content.contentURL = URL(string: "Your_Link")
let messageDialog = FBSDKMessageDialog()
messageDialog.delegate = nil
messageDialog.shareContent = content
if messageDialog.canShow() {
messageDialog.show()
}
.imageURL,。contentTitle,.contentDescription现已弃用
答案 1 :(得分:1)
试试这个:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"YOUR_LINK"];
content.imageURL = [NSURL URLWithString:@"SOME_IMAGE"];
content.contentTitle = @"Awesome title here!";
content.contentDescription = @"Some description maybe...";
content.quote = @"A nice quote here...";
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
messageDialog.delegate = nil;
[messageDialog setShareContent:content];
if ([messageDialog canShow]) {
[messageDialog show];
}