2014-11-21 1 views
0

Мое приложение было недавно отклонено, потому что я использую интеграцию с Google Plus Login с внешним браузером. Поэтому прочитайте несколько потоков и найдите решение для создания класса UIApplication для обработки внешнего браузера и используйте значение по умолчанию UIWebView. Я сделал все, но у меня есть проблема, чтобы открыть страницу входа в Google в UIWebView. Вот мой код.Войти с помощью google plus с открытием внешнего браузера в iPhone

LoginWithGoogle.h

#import <UIKit/UIKit.h> 
#define ApplicationOpenGoogleAuthNotification @"ApplicationOpenGoogleAuthNotification" 
@interface LoginWithGoogle : UIApplication 
@end 

LoginWithGoogle.m

#import "LoginWithGoogle.h" 
@implementation LoginWithGoogle 
- (BOOL)openURL:(NSURL*)url { 

    if ([[url absoluteString] hasPrefix:@"googlechrome-x-callback:"]) { 
     return NO; 

    } else if ([[url absoluteString] hasPrefix:@"https://accounts.google.com/o/oauth2/auth"]) { 

     [[NSNotificationCenter defaultCenter] postNotificationName:ApplicationOpenGoogleAuthNotification object:url]; 
     return NO; 
    } 

    return [super openURL:url]; 
} 
@end 

И я добавил LoginWithGoogle в качестве основного класса в info.plist. Я получаю уведомление и открываю UIWebView в другой класс. Теперь я хочу открыть окно входа в Google Plus в свой собственный интерфейс UIWebView, например, автоматически открывать в Safari или внешний браузер в shouldStartLoadWithRequest делегат UIWebView. Я попытался следующий код:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request 
navigationType:(UIWebViewNavigationType)navigationType 
{ 

    if ([[[request URL] absoluteString] hasPrefix:@"com.XXX.XXX:/oauth2callback"]) { 
     [GPPURLHandler handleURL:url sourceApplication:@"com.google.chrome.ios" annotation:nil]; 
     [self.navigationController popViewControllerAnimated:YES]; 
     return NO; 
    } 
    return YES; 

} 

Но что должно быть URL в коде выше? Если я ошибаюсь, то любезно посоветуйте мне, как открыть страницу входа в UIWebView.

ответ

0

1) создать подкласс UIApplication, который переопределяет OpenUrl:

.h

#import <UIKit/UIKit.h> 

#define ApplicationOpenGoogleAuthNotification @"ApplicationOpenGoogleAuthNotification" 

@interface Application : UIApplication 

@end 

.m

#import "Application.h" 

@implementation Application 

- (BOOL)openURL:(NSURL*)url { 

    if ([[url absoluteString] hasPrefix:@"googlechrome-x-callback:"]) { 

     return NO; 

    } else if ([[url absoluteString] hasPrefix:@"https://accounts.google.com/o/oauth2/auth"]) { 

     [[NSNotificationCenter defaultCenter] postNotificationName:ApplicationOpenGoogleAuthNotification object:url]; 
     return NO; 

    } 

    return [super openURL:url]; 
} 

@end 
  • это будет в основном предотвратить что-нибудь, чтобы быть открыт из Chrome на iOS
  • мы ловим вызов auth и перенаправляем его на наш внутренний UIWebView

2) в info.plist, добавить главный класс, и для него заявки (или как бы вы назвали класс)

3) поймать уведомления и открыть внутреннюю WebView

4) внутри WebView

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 

    if ([[[request URL] absoluteString] hasPrefix:@"com.XXX.XXX:/oauth2callback"]) { 
     [GPPURLHandler handleURL:url sourceApplication:@"com.google.chrome.ios"n annotation:nil]; 
     [self.navigationController popViewControllerAnimated:YES]; 
     return NO; 
    } 
    return YES; 
} 
  • или simmilar код, который обрабатывает ответ
  • вы можете использовать @ "com.apple.mobilesafari" в качестве источника. Параметр приложения
Смежные вопросы