I can successfully share video and picture using FBSDKMessengerSharer
shareVideo
and shareImage
methods.
When I go to share an .mp3 file using shareAudio
method, it seems to work as it should within my app, however when the file is sent in Facebook Messenger, it display error within facebook messenger when trying to play.
Any help would be amazing. I have been struggling with this for days.
Code to setup share button:
override func viewDidLoad() {
super.viewDidLoad()
let button = FBSDKMessengerShareButton.rectangularButtonWithStyle(FBSDKMessengerShareButtonStyle.Blue);
button.addTarget(self, action: #selector(_shareButtonPressed), forControlEvents: UIControlEvents.TouchUpInside);
self.view.addSubview(button);
}
shareButtonPressed function:
func _shareButtonPressed() {
let audioUrl = NSURL(string: "<URL_TO_MY_MP3>/214.mp3")
do {
let mp3Data = try NSData(contentsOfURL: audioUrl!, options: NSDataReadingOptions())
FBSDKMessengerSharer.shareAudio(mp3Data, withOptions: FBSDKMessengerShareOptions());
} catch {
print(error)
}
}
Problem was that the bytes in my MP3 files were not formatted correctly. Adding mp3 header bytes solved the problem.