I can't for the life of me find out how to simply open a Pinterest board (by launching the APP if it's installed) through an anchor within HTML.
I've taken a look at: https://developers.pinterest.com, but still can't find what i'm looking for. It seems most of the documentation out there is geared more towards the action of pinning an item, rather than viewing.
All I want to do is open a users profile. For example, i've dug up the following which works great for alternative social media links:
<a href="fb://profile/23050834961">Facebook</a>
<a href="twitter://user?screen_name=NHLBruins">Twitter</a>
<a href="instagram://user?username=nhlbruins">Instagram</a>
While I'm able to launch the Pinterest app, I'm unsure what the parameters would be passed to open a specific profile / board on Pinterest:
<a href="pinterest://">Pinterest</a>
Thanks to: http://handleopenurl.com/ for help with the above, but it seems Pinterest is absent. Any clues?
Looks like Pinterest has published an iOS SDK, and defined some URLS:
Pin
pinterest://pin/285063851385287883/
Board
pinterest://board/meaghanror/cats-cats-cats/
User
pinterest://user/carlrice/
See more at https://developers.pinterest.com/ios/
Working Code for Swift 4.x
func openSocialMedia(appURI : String, webURI : String){
let appURL = NSURL(string: appURI)!
let webURL = NSURL(string: webURI)!
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)
}
}
}
How to call
@IBAction func didPressInstagram(_ sender: Any) {
let appHandle = "instagram://user?username=erashukr"
let webHandle = "https://instagram.com/erashukr"
self.openSocialMedia(appURI: appHandle, webURI: webHandle)
}
@IBAction func didPressGplus(_ sender: UIButton) {
let appHandle = "gplus://plus.google.com/u/0/+Ashutoshkumarrr"
let webHandle = "https://plus.google.com/u/0/+Ashutoshkumarrr"
self.openSocialMedia(appURI: appHandle, webURI: webHandle)
}
@IBAction func didPressFacebook(_ sender: Any) {
let appHandle = "fb://profile?id=erashukr"
let webHandle = "https://facebook.com/erashukr"
self.openSocialMedia(appURI: appHandle, webURI: webHandle)
}
@IBAction func didPressTwitter(_ sender: UIButton) {
let appHandle = "twitter://user?screen_name=ace_ashu"
let webHandle = "https://twitter.com/ace_ashu"
self.openSocialMedia(appURI: appHandle, webURI: webHandle)
}
@IBAction func didPressPinterest(_ sender: UIButton) {
let appHandle = "pinterest://user/apple"
let webHandle = "https://www.pinterest.com/apple/"
self.openSocialMedia(appURI: appHandle, webURI: webHandle)
}
100% Working