Facebook app wont open up, facebook in safari opens instead. Using xCode 10.2.1
Deployment target running iOS 12.2
Edit: this code does achieve the desired objective for Instagram
Edit2: So on #bbrodsky's recommendation i changed "facebook" to "fb" in the URL link. The problem now is that it opens to my personal feed and not the business page i want it to open to.
Edit3: So ive gotten it to work. Opens up the facebook app, and goes to desired page. Had to change the appURL to "fb://profile/NUMERICFBID". I was able to get the numeric facebook ID for the page at this site https://findmyfbid.com/
Tried solutions from this post and others. Cant seem to find any recent answers to this question, as everything seems to be from earlier versions of iOS and swift/xCode. Unsure if things have changed. Have added the recommended code to the plist source file with no results.
How to open fb and instagram app by tapping on button in Swift
#IBAction func facebookButtonTapped(_ sender: UIButton) {
let screenName = "MYSCREENNAME"
let appURL = NSURL(string: "facebook://user?screen_name=\
(screenName)")!
let webURL = NSURL(string: "https://facebook.com/\
(screenName)")!
if UIApplication.shared.canOpenURL(appURL as URL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(appURL as URL, options:
[:], completionHandler: nil)
}
else { UIApplication.shared.openURL(appURL as URL)
}
}
else {
//redirect to safari because the user doesn't have
Instagram
if #available(iOS 10.0, *) {
UIApplication.shared.open(webURL as URL, options:
[:], completionHandler: nil)
}
else {UIApplication.shared.openURL(webURL as URL)
}
}
expected result is that the facebook app opens to the particular page. keep getting this error code.
2019-06-08 11:28:39.561051-0500 SocialMediaLinkPractice[9888:2173963] -canOpenURL: failed for URL: "facebook://user?screen_name=MYSCREENNAME" - error: "This app is not allowed to query for scheme facebook"
Add in Info.plist
First, you have to modify Info.plist to list instagram and facebook with LSApplicationQueriesSchemes. Simply open Info.plist as a Source Code, and paste this:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
<string>fb</string>
</array>
When you want to open the Facebook App and direct to a Facebook-Page, use the Page-ID. Here is a Link, where you could find them: https://www.facebook.com/help/1503421039731588
Schemes
fb://profile – Open Facebook app to the user’s profile OR pages
fb://friends – Open Facebook app to the friends list
fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)
fb://feed – Open Facebook app to the News Feed
fb://events – Open Facebook app to the Events page
fb://requests – Open Facebook app to the Requests list
fb://notes – Open Facebook app to the Notes page
fb://albums – Open Facebook app to Photo Albums list
Source: https://stackoverflow.com/a/10416399/8642838
SwiftUI-Code Version
Button(action: {
let url = URL(string: "fb://profile/<PAGE_ID>")!
let application = UIApplication.shared
// Check if the facebook App is installed
if application.canOpenURL(url) {
application.open(url)
} else {
// If Facebook App is not installed, open Safari with Facebook Link
application.open(URL(string: "https://de-de.facebook.com/apple")!)
}
}, label: {
Text("Facebook")
})
if you want to open a specific profile on Facebook app, you have to use
let username = "your Facebook name"
let appURL = URL(string: "fb://profile/\(username)/?id=\(username)")!
otherwise it will not work.
I believe you want to use "fb://" and not "facebook://"
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 trying to integrate UPI payment in my app. i have seen some apps where they are providing google pay and phone pe buttons, if they are installed in the device. on clicking button, particular app is opening.
I need to implement similar experience in my ios app.
i have tried generating URL as specified in NPCI doc https://www.npci.org.in/sites/all/themes/npcl/images/PDF/UPI_Linking_Specs_ver_1.5.1.pdf
i tried using UIApplication.shared.open(url, options: [:], completionHandler to open the UPI app. every time its opening whatsapp only.
How can we open phone pe / google pay app based on users selection without entering payer's UPI id.
It is opening WhatsApp because Generic Intent does not work on iOS.
For Gpay you could try below codes:
#IBAction func Gpay(sender: AnyObject) {
guard let url = NSURL(string: "tez://upi/pay?pa=test#dcb&cu=INR&mc=0000&appName=TEST&tn=To&am=1.0&pn=TEST&tr=TEST-1574159602900") else {
return
}
UIApplication.shared.open(url as URL)
}
You can get deeplink url of PhonePe as below
PhonePeSDK.shared().deeplinkUrl
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 would like to send a link with my message to allow the user to open the app store to install the app or use a deep link to link into a certain piece of content in my app, similar to the Apple Music iMessage App. I am currently using:
var messagee:MSMessage = message.url = URL(string: "https://itunes.apple.com/us/app/reaction-timer-game/id572319874?ls=1&mt=8")
template.image = game1Image.image!
template.imageTitle = "Game 1"
template.imageSubtitle = "\(bestScore1[0])"
But when I tap on the the image the iMessage app opens instead of the URL. Is this possible and if so, how can I do this?
Should I be sending the URL with this:
let url = URL(string: "urlData")
self.activeConversation?.insertAttachment(url!, withAlternateFilename: "URL", completionHandler: { (error) in
if error != nil {
print("Error")
} else {
print("Sent")
}
})
Thank you
I don't think that's possible. If you try to open any URL or a URL scheme, it will open your main iOS app if you have one.
In my case I wanted to display a web page so what I did is just use a UIWebView instead of opening Safari directly.
iMessage will already display your app link if the recipient doesn't have it installed. This helps app discoverability but you can't automatically open your app in the App Store.
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
}
}