I want to open user linedIn profile(in linkedIn Native App) from my App.
I tried this but its just opening linekdin App but not profile page: URL Scheme for Linkedin
I have added URLSchemes as well
<key>LSApplicationQueriesSchemes</key>
<array>
<string>linkedin</string>
</array>
This is my code
if let linkedinUrl = URL(string: "linkedin://profile?id=parmarvhv"),
UIApplication.shared.canOpenURL(linkedinUrl) {
UIApplication.shared.open(linkedinUrl, options: [:], completionHandler: nil)
}
LinkedIn Web Url is this: https://www.linkedin.com/in/parmarvhv/
What is the correct way to open user profile?
This code works for swift 5:
Opening a LinkedIn page:
linkedin://company/binance
Opening a LinkedIn profile:
linkedin://profile/binance
Well, it's not documented. so you can't rely on it.
But, using linkedin://in/{username} works for me.
Related
I have a WKWebView, the webview will load a link like https://qr.payme.hsbc.com/2/XXXXYYYZZZ.
And there two possible results when the link is loaded,
case 1 is an app called Payme will be opened when user has installed Payme app;
case 2 is webview will be redirected to a static page https://payme.hsbc.com/ when user has not installed Payme app.
My question is how can I know if the Payme app is opened?
You could use deep linking or the apple recommended universal linking to check if an app is installed in a device. With deep linking what you need to do is to acquire a schema of the app that the app has already added. And you could check if the schema can be opened just like you would do for any other type of URLs. Here is an example:
let appSchemeString = "com.myAppScheme://"
let url = URL(string: appSchemeString)!
if UIApplication.shared.canOpenURL(url) {
print("App is present")
} else {
print("App is not")
}
You need to update your info.plist file to include the schemes you'll be opening in the application. You should append this:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.myAppScheme</string>
</array>
Here is an entire youtube video link regarding this.
Also, checkout universal-linking.
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://"
I need to open google map in my iOS App. If google map is installed, navigate to google map, otherwise redirect to AppStore for install Google Maps. This is my tries
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
print("app found")
UIApplication.shared.open(URL(string: "comgooglemaps://?center=9.9894,76.5790&zoom=14&views=traffic&q=\(lattitude),\(longitude)")!, options: [:], completionHandler: nil)
}else {
showAlertWithTitle(title: "App not found", message: "You need to install Google Map", fromViewController: self)
print("Can't use comgooglemaps://")
}
One option is to use UIApplication openURL with a URL that starts with http://maps.google.com.
If the user has the Google Maps app installed, the app will be launched.
If the user doesn't have the app installed, Safari will be opened to the Google maps page. Besides showing the map, that page will give the user the option to go to the App Store to get the app if desired.
This approach has the most flexibility and offers the user the greatest choice of what they want to do.
An alternative is to use the approach you stared and check for the comgooglemaps scheme. In your else, you can display a SKStoreProductViewController passing in the app id for the Google Maps app (585027354).
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
print("app found")
UIApplication.shared.open(URL(string: "comgooglemaps://")!, options: [:], completionHandler: nil)
}else {
UIApplication.shared.openURL(NSURL(string: "itms://itunes.apple.com/us/app/google-maps-transit-food/id585027354?mt=8")! as URL)
print("Can't use comgooglemaps://")
}
Also please add below code in your info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>
Please add code and let me know, Above code will open google map if installed in your device otherwise it will redirect to app store.
i defined a deep-link in info.plist like this :
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.myapp.customer</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp.com</string>
</array>
</dict>
</array>
but in Safari there's no reaction to this link and this message shows up :
Safari cannot open the page because the server can not be found
Everything is checked and i did as tutorials and still nothing happens!
The CFBundleURLSchemes field should be filled with a scheme, not a url. Schemes come before the url to tell the browser what action to take. For example, https:// is a scheme that tells the browser to establish a secure connection. An Apple URI scheme is simply you telling the browser that you want URLs with your custom scheme (i.e. customScheme://) to be handled by your app. HTTP and HTTPS are reserved for Safari on iOS. To allow customScheme://example/path to open your app. Just change that field to customScheme.
If you would like to register normal web URLs to handle your links you will have to integrate Universal Links. These can be a pain to set up so I recommend using the Branch iOS SDK. Their deep linking is free and provides more features on top of Universal Links.
Make sure you have this method in AppDelegate.Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if url.scheme != nil && url.scheme!.hasPrefix(""){
//Deep linking link should be like this : 'yourAppScheme'
if(url.host?.contains("page"))!{
if(url.path.contains("/yourhoststring")){
// do some work
}
}
}
//default
return false
}
Your Url scheme should be like this : [scheme]://[host]/[path]
Here is the link for detailed tutorial:
http://blog.originate.com/blog/2014/04/22/deeplinking-in-ios/
I have an application in IOS in which there is a Facebook Login Button.
when ever user clicks this Facebook login button My app redirects the user to the Facebook App installed in my device. So I want to logout the user from the application as soon as he leaves the facebook app and comes to my app.
i redirect the user to the facebook app using
NSUrl url = NSUrl.FromString("fb://profile/<id>");
UIApplication.SharedApplication.OpenUrl(url);
I found the Facebook login documentation. As the documentation described, I think you have added the CFBundleURLTypes, like this:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb[APP_ID]</string>
</array>
</dict>
</array>
It means that Facebook will trigger the openURL to return back to your app via the URLScheme you have set here.
So, you can override OpenUrl(UIApplication app, NSUrl url, NSDictionary options) in AppDelegate.cs, and the parameters url or options contain the information related to Facebook. So, you can identify the resource.
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
Console.WriteLine(url);
Console.WriteLine(options);
return true;
}
According to this, you can do the action you want when return back from Facebook.
Are you using the Xamarin Facebook SDK? If yes you can do this to log out:
new LoginManager().LogOut();