Google + 登录 iOS 应用商店拒绝使用 google sdk v3.x

Google + login iOS App rejection from appstore using google sdk v3.x

经过大量挖掘后,我在这里发布我的问题。我在我的应用程序中使用 google 登录最新的 sdk,该应用程序支持 iOS 8+。我目前使用的是 Xcode 7.2。最近我的应用程序被拒绝了,原因是许多用户过去都经历过的非常普遍的原因:

来自应用商店
我们注意到用户被带到 Safari 以登录或注册帐户,这提供了糟糕的用户体验。具体来说,Google 登录会将用户带到 Safari 进行登录。

后续步骤

10.6请修改您的应用程序,使用户能够在应用程序中登录或注册帐户。

我们建议实施 Safari View Controller API 以在您的应用程序中显示 Web 内容。 Safari View Controller 允许显示 URL 并检查来自应用程序中嵌入式浏览器的证书,以便客户可以验证网页 URL 和 SSL 证书以确认他们正在输入他们的登录凭据进入合法页面。
END

我已经知道这种拒绝,因为 Apple 已经拒绝了很多在 Safari 浏览器中取消登录流程的应用程序。这里有一些link供参考
https://code.google.com/p/google-plus-platform/issues/detail?id=900
https://github.com/Torsten2217/google-plus-platform/issues/900

还有更多 link 可以在 Internet 上轻松找到

2015 年 5 月 Google 发布了带有本机 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 中的 link 有一个 Try Sign-In for iOS 样本,我试过了。它现在仅在 iOS 9 中打开本机 SFSafariViewController,但在 iOS 8 中,登录流程再次从应用程序外部转到 Safari 浏览器。

在 apple 审阅者的评论中要求使用 SafariViewController 但控件的可用性来自 iOS 9 及更高版本 。这里是linkhttps://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
如何使用 iOS 8 中的最新 google sdk 实现此目的?
评论者都没有提到 iOS 版本 he/she 正在测试。

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

终于用最新的Google+ Sign SDK解决了这个问题,应用也通过了Apple的审核。我发布了 iOS 9iOS 8.
Use [=43] 的解决方案=]CocoaPods 用于集成。

pod 'Google/SignIn'

要开始登录,您必须执行 开始集成 部分 here

中提到的完全相同的步骤

现在,在 添加登录 部分,我想在 UIViewController 的自定义 class 中使用一些自定义按钮来启动登录过程。在 Google 的开发者 link 中,他们仅在 AppDelegate 中重定向。所以为了避免这种情况,我不会在 AppDelegate class

中使用 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 class 即 LoginViewController,实施 GIDSignInDelegateGIDSignInUIDelegate

class LoginViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {

}

Google + 登录有一个自定义 UIButton,其定义是

@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()
    }

}

现在 delegate 方法的实现 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
}

现在这将在 iOS 8 和 9 中工作,而无需将您的应用程序移到 Safari 之外以在 Google + 中登录。