I want to give the user a link to my app's Facebook page so the user can like it. I don't want there to be any login, permissions or any other social functionality. I thought I could use a simple link like this:
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.facebook.com/MyAppPage")!)
I thought this would take the user to the Facebook app and open my app's page, or if the user doesn't have the Facebook app installed, take them to Safari. It did go to the Facebook app, but didn't go to my page. Is there a simple way to do this? Do I need to implement the Facebook SDK or Social Framework?
Here's the solution I use. Your app will have two links, one for the FB app and one for the browser. This will check to see if the device supports the FB app link first and if not show it in the browser (if available).
let urls = ["fb://profile/xxxxxxxx",
"https://m.facebook.com/xxxxxxx"];
let application = UIApplication.sharedApplication()
for urlString in urls {
let url = NSURL(string: urlString)
if(application.canOpenURL(url!))
{
application.openURL(url!)
return
}
}
Related
The goal is simple, I want to allow a user to connect their Facebook page to the iOS app i've been developing so that when they press a button in my app, it will navigate them to the appropriate Facebook page. If the user has the Facebook app installed, it will launch and use the Facebook app and if not, it will use Safari.
I was able to implement this exact functionality for another app with the following code:
if let facebookPageId = facebookPageIdTextField.text {
let facebookHook = "fb://profile/" + facebookPageId
if let url = URL(string: "\(facebookHook)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.open(URL(string: "https://www.facebook.com/placeholder")!)
}
}
}
However, I had to browse the Facebook HTML source code in order to find the value to use for facebookPageId and asking a user to dive into the source code seems pretty impractical.
Does Facebook not want developers to have access to this kind of functionality? Has anyone found an easy fix for this?
Im using FBSDKShareKit (4.22.1), i'm trying to share photo with the following code:
let photo = FBSDKSharePhoto()
photo1.imageURL = URL(string: "sample url")
photo.isUserGenerated = false
let photoContent = FBSDKSharePhotoContent()
photoContent.photos = [photo]
FBSDKShareDialog.show(from: self, with: photoContent, delegate: nil)
but it only works when the native Facebook app is installed on the phone.
I also tried to show the content with Share Button instead of Share Dialog like:
var shareButton = FBSDKShareButton()
shareButton.shareContent = photoContent
shareButton.center = self.view.center
self.view.addSubview(shareButton)
it didn't work, if app was not installed either.
i want the FBSDK i used in my app, opens Safari when Facebook app is not installed, it opens safari by default for FBSDKShareLinkContent, but not working for FBSDKSharePhotoContent.
does anyone know what is the problem?
I have implemented another way to share photos using Graph API. It was very helpful. Here is a link.
Just what you need is to take the permissions from the user to publish_actions
before posting.
Also there is no native facebook app installed. Just got logged in through Browser.
Well, I found the answer in Facebook developer website, which is:
Photos
People can share photos from your app to Facebook with the Share
Dialog or with a custom interface:
Photos must be less than 12MB in size
People need the native Facebook for iOS app installed, version 7.0 or higher
you can also ask for "publish_actions", you need to login twice, first with readPermission for email, then when user wants to share a post loginWithPublishPermission for "publish_actions". the point is that you have to add "publish_actions" first of all in your Facebook developer account.
I am wondering if it is possible to share/send a url link and other media from iOS app via Facebook Messenger app without having to open UIActivityViewController's activity sheet first, which in addition shows a number of other apps which can handle the intended data and does not allow to exclude apps only UIActivityTypes. I would like to present a FB Messenger dialog with pre-filled url link immediately after a button tap, so no dialog with multiple other apps.
Facebook documentation suggests we should use FB SDK in such cases: https://developers.facebook.com/docs/sharing/ios#message. But what is beyond me is that iOS seems to have a "native access" to the Messenger app (and other apps), but there is no good API which could facilitate some UI customisation.
Any idea if there is a way to directly open FB Messenger with pre-filled message without needing to present UIActivityViewController's activity sheet or installing FB SDK?
EDIT: Let me clarify, I would like to share a url link or other media, it is not necessary that the message is pre-filled with text.
You can share a link via messenger in this way
let urlStr = String(format: "fb-messenger://share/?link=%#", sharelink!)
let url = NSURL(string: urlStr)
if UIApplication.shared.canOpenURL(url! as URL) {
UIApplication.shared.open(url! as URL, options: [:]) { (success) in
if success {
print("Messenger accessed successfully")
} else {
print("Error accessing Messenger")
}
}
} else {
// show Install Messenger
}
After lots of searching I can confirm that it is not possible to share text or other media via Facebook Messenger without using their FB SDK as they do not provide URL schemes for that.
I've been trying to go with Applink protocol provide linkback referal from Facebook to original app. The way I've contructed destination link is:
fb://profile/123456?al_applink_data=<encoded_json>
where is url encded string:
{"target_url":"http:\/\/www.facebook.com/123456","referer_app_link":{"url":"myawesomeapp:\/\/member\/bojan-babic","app_name":"MyAwesomeApp"}}
In app itself this is opened in following manner:
let application = UIApplication.sharedApplication()
let targetUrl:NSURL = NSURL(string: targetUrlString)!
application.openURL(targetUrl)
Outcome is that myawesome opens native iOS app, but I do not see "Touch to get back to MyAwesomeApp" header within Facebook App.
What would be proper process to achieve link back to original app?
Note: I've tried same approach with Pinterest iOS app as well
I want to connect users' Instagram accounts to my app, and be able to make them follow other users (that s/he chooses) on Instagram; or at least triggering the Instagram app and go to users' profile. I am currently using Swift and the documentations out there are not so clear. Is it actually possible to do what I want to do? If so, how can I do it? Thanks in advance for your helps.
This function will do the job:
if instagram app is not installed, then it will open the webpage of instagram in safari.
If the app is installed, it opens the page you want in instagram app:)
func openInstagram() {
var instURL: NSURL = NSURL (string: "instagram://user?username=Instagram")! // Replace = Instagram by the your instagram user name
var instWB: NSURL = NSURL (string: "https://instagram.com/instagram/")! // Replace the link by your instagram weblink
if (UIApplication.sharedApplication().canOpenURL(instURL)) {
// Open Instagram application
UIApplication.sharedApplication().openURL(instURL)
} else {
// Open in Safari
UIApplication.sharedApplication().openURL(instWB)
}
}
Here is document page from Instagram for ios developers (you can find how to open user Instagram profile): https://instagram.com/developer/mobile-sharing/iphone-hooks/
Library that may help you (connect user accounts, follow): https://github.com/shyambhat/InstagramKit