简体   繁体   English

用于iOS Safari上的Pinterest的自定义URL方案以打开板URL

[英]Custom URL scheme for Pinterest on iOS Safari to open board URL?

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. 我一生都无法找到如何通过HTML中的锚点简单地打开Pinterest板(如果已安装,则通过启动APP)。

I've taken a look at: https://developers.pinterest.com , but still can't find what i'm looking for. 我看了一下: https : //developers.pinterest.com ,但是仍然找不到我想要的东西。 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: 虽然我可以启动Pinterest应用程序,但是我不确定在Pinterest上打开特定配置文件/板时将传递哪些参数:

<a href="pinterest://">Pinterest</a>

Thanks to: http://handleopenurl.com/ for help with the above, but it seems Pinterest is absent. 感谢: http : //handleopenurl.com/提供上述帮助,但似乎Pinterest缺失。 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/ 看起来Pinterest已发布了iOS SDK,并定义了一些URL: Pin pinterest://pin/285063851385287883/ Board pinterest://board/meaghanror/cats-cats-cats/ User pinterest://user/carlrice/

See more at https://developers.pinterest.com/ios/ https://developers.pinterest.com/ios/上查看更多

Working Code for Swift 4.x 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 100%工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM