10

在挖掘了很多之后,我在这里发布了我的问题。我在我的应用程序中使用谷歌登录最新的 sdk,并且该应用程序支持 iOS 8+。我目前正在使用 Xcode 7.2。最近我的应用程序被拒绝了,原因是许多用户过去经历过的非常常见的原因:

FROM APPSTORE
我们注意到用户被带到 Safari 登录或注册帐户,这提供了糟糕的用户体验。具体来说,谷歌登录将用户带到 Safari 登录。

下一步

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

我们建议实现 Safari View Controller API 以在您的应用程序中显示 Web 内容。Safari 视图控制器允许显示 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

还有一些您可以在 Internet 上轻松找到的链接

2015 年 5 月,Google 发布了一个带有原生 Web 视图的新 sdk。此处列出了完整的集成过程http://www.appcoda.com/google-sign-in-how-to/
它在 iOS 8 上运行良好,并且还展示了一个控制器。

现在我正在使用我通过 CocoaPods https://developers.google.com/identity/sign-in/ios/start
安装的最新 google sdk 来自 google 的上述链接有一个Try Sign-In for iOS示例,我尝试过。它现在SFSafariViewController仅在 iOS 9 中打开本机,但在 iOS 8 中,登录流程再次从应用程序外部转到 Safari 浏览器。

在评论中苹果审阅者要求使用SafariViewController但该控件的可用性来自iOS 9 及更高版本。这是链接https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
如何在 iOS 8 中使用最新的 google sdk 实现这一点?
评论者也没有提到他/她正在测试的 iOS 版本。

现在任何人都可以帮我解决这个问题。如何在 iOS 8(Google 登录页面的本机当前控制器)中进行管理。

4

1 回答 1

18

最后用最新的 Google+ Sign SDK 解决了问题,并且该应用程序也得到了 Apple 的批准。我正在发布适用于iOS 9iOS 8的解决方案。
使用CocoaPods进行集成。

pod 'Google/SignIn'

要开始登录,您必须执行此处开始集成部分中提到的完全相同的步骤

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

我只会在以下两种方法中进行更改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 {

}

有一个用于 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()
    }

}

现在实现 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 + 中登录。

于 2016-04-16T15:56:13.483 回答