处理SFSafariViewController中的popup窗口/选项卡

我在我的应用程序中实现了一个SoundCloudloginstream程。 该应用程序打开https://soundcloud.com/connectSFSafariViewControllerredirect_uri使用我的应用程序的自定义URLscheme来接收响应。 它可以直接使用SoundCloudlogin,但在尝试使用“使用Googlelogin”button时失败。

在Safari中,该button通过Googlelogin页面打开一个新选项卡(在桌面上popup),然后通过postMessage传回到SoundCloud选项卡。 如果您使用iOS Safari应用程序,则此loginstream程正常工作,但在SFSafariViewController失败(单击该button可转至带有Googleurl的白页: https://accounts.google.com/o/oauth2/auth?... )。

现在我的解决方法是build议使用Google的用户点击SFSafariViewController上的Safari图标来完成Safari应用程序中的loginstream程,但是我想知道是否有办法在不离开我的应用程序的情况下处理这个问题。

那么,如果我使用UIWebView ,则可以在用户通过Google进行身份validation后,从Google获取最终的oauth响应。 但是,我们如何将其转回到SoundCloud(例如soundcloud.com/connect/via/google_plus/returning

 - (void) webViewDidFinishLoad:(UIWebView*)inWebView { NSString* str = [inWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('response-form-encoded').value"]; if ( str.length > 0 ) { NSDictionary* params = parseURLParams( str ); NSLog( @"%@", params ); } } 

输出:

 { "access_token" = "ya2...<removed>...4g"; authuser = 0; code = "4/sU_g7....<removed>...fnRELA"; "expires_in" = 3600; "id_token" = "eyJhb...<removed>...DA"; prompt = none; scope = "https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/plus.login+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/plus.moments.write+https://www.googleapis.com/auth/plus.me+https://www.googleapis.com/auth/plus.profile.agerange.read+https://www.googleapis.com/auth/plus.profile.language.read+https://www.googleapis.com/auth/plus.circles.members.read"; "session_state" = "c8703a085b885bbe8c8d0e29277b0c2fdf9c6c87..65aa"; state = "392921654%7C0.288515904"; "token_type" = Bearer; } 

启动Googlelogin步骤的URL如下 – 为了方便起见,我在下面解码了URL转义编码:

  https://accounts.google.com/o/oauth2/auth?client_id=984739005367.apps.googleusercontent.com&response_type=code token id_token gsession&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.profile&state=425511939|0.2912748339&access_type=offline&request_visible_actions=http://schemas.google.com/AddActivity http://schemas.google.com/ListenActivity http://schemas.google.com/CreateActivity&after_redirect=keep_open&cookie_policy=single_host_origin&prompt=none&include_granted_scopes=true&proxy=oauth2relay751149297&redirect_uri=postmessage&origin=https://soundcloud.com&gsiwebsdk=1&authuser=0&jsh=m;/_/scs/apps-static/_/js/k=oz.gapi.en.TA32fes-0yU.O/m=__features__/am=AQ/rt=j/d=1/rs=AGLTcCOuWXPCbMjoOmrZx_gBsAG8J20NLA