【问题标题】:Open Facebook group page using Facebook app on IOS在 IOS 上使用 Facebook 应用打开 Facebook 群组页面
【发布时间】:2014-11-13 04:51:42
【问题描述】:

在我的 IOS 应用中,我想将 facebook 应用打开到 GROUP。

在 Android 上,我只是打开了以下 URL:

“fb://group/12345678/”(我在这个例子中替换了组 id)

这在 android 上运行良好。在 IOS 中尝试同样的事情时:

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://group/12345678/"]];

Facebook 应用程序打开,但我得到:

“您点击的链接可能已损坏,或者该页面可能已被删除。”

我找不到任何其他方法可以从 IOS 向公共 facebook 群组开放。

谢谢

【问题讨论】:

    标签: ios facebook


    【解决方案1】:

    您可以使用 id 来使用 page,如下所示:

    ObjC

    NSURL *url = [NSURL URLWithString:@"fb://page/?id=12345678"]
    [[UIApplication sharedApplication] openURL:url];
    

    Swift3

    func openFBGroup(groupID: String = "12345678") -> Bool {
        guard let url = URL(string: "fb://page/?id=\(groupID)") else { return false }
        guard UIApplication.shared.canOpenURL(url) else { return false }
        UIApplication.shared.open(url, options: [], completionHandler: nil)
        return true
    }
    

    Swift4

    @discardableResult func openFBGroup(groupID: String = "12345678") -> Bool {
        guard let url = URL(string: "fb://page/?id=\(groupID)") else { return false }
        guard UIApplication.shared.canOpenURL(url) else { return false }
        return UIApplication.shared.openURL(url)
    }
    

    【讨论】:

    • 我如何找到 fb groupID ?
    • @dip 它在组的 URL 中。检查最后的数字
    • 我必须使用“fb://group/?id=”来获得想要的结果(2021,Swift 5)。
    【解决方案2】:

    您可以使用个人资料和群组ID在Facebook应用中打开Facebook群组,详细代码:

    NSURL *facebookGroupURL = [NSURL URLWithString:@"fb://profile/123456/"];
    if ([[UIApplication sharedApplication] canOpenURL:facebookGroupURL]) {
        [[UIApplication sharedApplication] openURL:facebookGroupURL];
    }
    else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/groups/123456/"]];
    }
    

    浏览: enter image description here

    手机: enter image description here

    它适用于 Xcode 9.1/iOS 11.1.2

    【讨论】:

      【解决方案3】:

      要在 facebook 应用中打开群组,您只需要打开完整的 url:

      NSURL *url = [NSURL URLWithString:@"https://www.facebook.com/gropId"]
      [[UIApplication sharedApplication] openURL:url];
      

      改为https://fb.com/gropId

      【讨论】:

        【解决方案4】:

        尝试使用“个人资料”而不是“群组”(例如URLWithString:@"fb://profile/144754840")。

        【讨论】:

        • 这只是在 Facebook 应用程序中加载一个完全空白的页面。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-10
        • 1970-01-01
        • 1970-01-01
        • 2014-10-07
        • 1970-01-01
        • 2021-06-05
        相关资源
        最近更新 更多