使用Google SDK v3.x登录iOS应用程序被App Store拒绝

10
在大量研究后,我在此发布我的问题。我在我的应用中使用Google最新的sdk进行登录,该应用支持iOS 8+。我目前正在使用Xcode 7.2。最近,我的应用因为非常普遍的原因被拒绝了,许多用户过去也经历过类似情况: 来自App Store: 我们注意到用户被带到Safari进行登录或注册帐户,这会给用户带来不良的用户体验。具体来说,Google登录会带用户到Safari进行登录。
下一步 10.6 请修改您的应用程序,以使用户能够在应用程序中登录或注册帐户。
我们建议实现Safari View Controller API,在应用程序中显示网页内容。 Safari View Controller允许在应用程序中嵌入浏览器并显示URL以及检查证书,以便客户可以验证网页URL和SSL证书,以确认他们输入其登录凭据的是合法页面。 结束

我已经知道了,苹果公司拒绝了很多在Safari浏览器中跳过“登录流程”的应用程序。以下是一些参考链接:
https://code.google.com/p/google-plus-platform/issues/detail?id=900
https://github.com/Torsten2217/google-plus-platform/issues/900

还有更多的链接可以在互联网上轻松找到。

2015年5月,谷歌发布了一个带有本地Web视图的新软件开发工具包(SDK)。整个集成过程在这里列出:http://www.appcoda.com/google-sign-in-how-to/
它在iOS 8上运行良好,并且也提供了一个控制器。

现在我正在使用通过CocoaPods安装的最新的Google SDK。https://developers.google.com/identity/sign-in/ios/start
上面的链接是来自Google的一个尝试iOS登录示例,我已经尝试过了。在iOS 9中,它现在打开了本地的SFSafariViewController,但在iOS 8中,登录流程又跳转到Safari浏览器之外。

在评论中,苹果评审员要求使用SafariViewController,但该控件的可用性仅限于iOS 9及以上版本。这里是链接https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
如何在iOS 8中使用最新的Google SDK实现此操作?
评审员没有提及他/她测试的iOS版本。

现在有谁能帮我解决这个问题。如何在iOS 8中管理Google登录页面的本机显示控制器。


@JAL 哥们,那是2013年的帖子了。现在情况已经大不相同了。请重新阅读我的问题,并寻找“SFSafariView”这个词。 - Rajan Maheshwari
为什么不阅读链接的问题。SFSafariViewController 仅适用于 iOS 9 及以上版本。对于 iOS 8 及以下版本,您的答案在链接的问题中。 - JAL
@JAL 这是苹果审核员实现 SFSafariViewController 的答案。这也是我发布的整个问题,即如何使用最新的 Google SDK 解决此问题。根据新的 SDK,我们现在不再使用 GTMOAuth2ViewControllerTouch。在 G+ 登录 SDK 的 API 参考列表中,我们甚至没有 GPPSignIn。我还提到了 2015 年 5 月推出的 Google SDK 失败的情况。 - Rajan Maheshwari
我目前也遇到了同样的问题,真的很令人沮丧。我正在使用最新的Google登录SDK,但在iOS 9中登录谷歌时它不会显示SFSafariViewController。你有没有做什么特别的事情来打开SFSafariViewController? - tyegah123
@tyegah123 我已经成功解决了iOS 9和8的问题,应用程序现在已经上线。我很快会发布答案。 - Rajan Maheshwari
@tyegah123,我已经发布了完整的解决方案。请看一下。 - Rajan Maheshwari
1个回答

18

最终,我们使用最新的Google+ Sign SDK解决了问题,并且该应用程序也已被Apple批准。我将为 iOS 9iOS 8发布解决方案。
请使用CocoaPods进行集成。

pod 'Google/SignIn'

要开始登录,您必须按照“开始集成”部分此处提到的完全相同的步骤进行操作。

现在,在“添加登录”部分中,我想在UIViewController的自定义类中添加一些自定义按钮以启动登录过程。在Google的开发者链接中,他们只重定向到AppDelegate。所以为了避免这种情况,我将不会在我的AppDelegate类中使用GIDSignInDelegate

我将仅对AppDelegate的以下两个方法进行更改。

//This is available for iOS 9 and above. So we have to use this method if we are integrating Google Sign In in iOS 9
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject])

//This is available prior iOS 9 and is available for iOS 8,7 etc. This is a deprecated method for iOS 9. You have to override this too if your app supports iOS 8 platform.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool

因此,定义如下:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {

    if #available(iOS 9.0, *) {
        return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as? String)
    } else {
        // Fallback on earlier versions
    }
    return true
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

    return GIDSignIn.sharedInstance().handleURL(url,sourceApplication: sourceApplication,annotation: annotation)
}

现在我们来到了自定义的UIViewController类,即LoginViewController,实现GIDSignInDelegateGIDSignInUIDelegate

class LoginViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {

}

有一个自定义的UIButton用于Google +登录,其定义为:

@IBAction func googleLoginButtonPressed(sender: AnyObject) {

    // Initialize sign-in
    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)

    //assert(configureError == nil, "Error configuring Google services: \(configureError)")
    if configureError != nil {
     //Handle your error
    }else {
        GIDSignIn.sharedInstance().shouldFetchBasicProfile = true
        GIDSignIn.sharedInstance().clientID = kClientId
        GIDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance().uiDelegate = self

        //This did the trick for iOS 8 and the controller is presented now in iOS 8
        //We have to make allowsSignInWithBrowser false also. If we dont write this line and only write the 2nd line, then iOS 8 will not present a webview and again will take your flow outside the app in safari. So we have to write both the lines, Line 1 and Line 2
        GIDSignIn.sharedInstance().allowsSignInWithBrowser = false  //Line 1
        GIDSignIn.sharedInstance().allowsSignInWithWebView = true   //Line 2

        GIDSignIn.sharedInstance().signIn()
    }

}

现在Google+登录已经实现了委托方法

func signIn(signIn: GIDSignIn!, dismissViewController viewController: UIViewController!) {
    self.dismissViewControllerAnimated(true) { () -> Void in       
    }
}

func signIn(signIn: GIDSignIn!, presentViewController viewController: UIViewController!) {
    self.presentViewController(viewController, animated: true) { () -> Void in
    }
}

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
    if (error == nil) {

        // Perform any operations on signed in user here.
        let userId = user.userID                  // For client-side use only!
        let idToken = user.authentication.idToken // Safe to send to the server
        let fullName = user.profile.name
        let givenName = user.profile.givenName
        let familyName = user.profile.familyName
        let email = user.profile.email
    } else {
        print("\(error.localizedDescription)")
    }
}

func signIn(signIn: GIDSignIn!, didDisconnectWithUser user: GIDGoogleUser!, withError error: NSError!) {
      //Perform if user gets disconnected
}

现在,您可以在不将应用移动到Safari上进行Google+登录目的的情况下,在iOS 8和9中使用此功能。


非常感谢!我现在正在尝试它。但是,我很好奇,你的应用程序内是否有谷歌或类似的共享功能? - tyegah123
为此,您不能使用Google登录。您必须使用Google分享SDK。 - Rajan Maheshwari
不,我也没有使用那个分享功能。这是因为即使我使用了Google Sign In SDK,苹果仍然说它是Google+ SDK,这也是应用被拒绝的原因之一。所以我想知道你是否在你的应用程序中使用了某种共享功能。但无论如何,非常感谢你的帮助。我终于让我的应用程序工作了。:D - tyegah123
@tyegah123,谷歌+苹果SDK与登录SDK相同。太好了。如果它对您有帮助,请点赞答案。 - Rajan Maheshwari

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接