From 348c6f24a4639b7a35e5b3f9edafce8079f6c160 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Thu, 17 Mar 2016 17:02:10 -0700 Subject: [PATCH] Allow third-party services to listen to openURL on iOS and support Google Sign-In --- sky/BUILD.gn | 5 +++++ sky/services/dynamic/README.md | 2 +- sky/shell/platform/ios/FlutterAppDelegate.mm | 21 ++++++++++++++++++++ sky/tools/gn | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sky/BUILD.gn b/sky/BUILD.gn index 7286d878e7f..dec693b28bf 100644 --- a/sky/BUILD.gn +++ b/sky/BUILD.gn @@ -7,6 +7,7 @@ import("//sky/engine/bindings/bindings.gni") declare_args() { enable_gcm = false enable_firebase = false + enable_google_sign_in = false } group("sky") { @@ -48,4 +49,8 @@ group("sky") { if (enable_gcm) { deps += [ "//third_party/gcm:gcm" ] } + + if (enable_google_sign_in) { + deps += [ "//third_party/google_sign_in" ] + } } diff --git a/sky/services/dynamic/README.md b/sky/services/dynamic/README.md index c44f29ef16f..a0d96a5beb0 100644 --- a/sky/services/dynamic/README.md +++ b/sky/services/dynamic/README.md @@ -1,4 +1,4 @@ Flutter Dynamic Services Loader =============================== -Third party service implementations are packaged as dylibs. Each dylib implementation needs to import just one file (`dynamic_service_dylib.h`) and implement `FlutterServicePerform` to provide the service implementation. In order to build the dylib, the build step needs the `//sky/services/dynamic:dylib` GN rule. \ No newline at end of file +Third party service implementations are packaged as dylibs. Each dylib implementation needs to import just one file (`dynamic_service_dylib.h`) and implement `FlutterServicePerform` to provide the service implementation. In order to build the dylib, the build step needs the `//sky/services/dynamic:sdk_lib` GN rule. diff --git a/sky/shell/platform/ios/FlutterAppDelegate.mm b/sky/shell/platform/ios/FlutterAppDelegate.mm index e88f7cbcb52..d8e57eb3e92 100644 --- a/sky/shell/platform/ios/FlutterAppDelegate.mm +++ b/sky/shell/platform/ios/FlutterAppDelegate.mm @@ -58,4 +58,25 @@ NSURL* URLForSwitch(const char* name) { return YES; } +// Use the NSNotificationCenter to notify services when we're opened with URLs. +// TODO(jackson): Revisit this API once we have more services using URLs to make +// it more typed and less brittle +- (BOOL)application:(UIApplication *)app + openURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + annotation:(id)annotation +{ + NSDictionary *dict = [@{ + @"handled": [NSMutableDictionary dictionary], + @"url": url, + @"sourceApplication": sourceApplication, + } mutableCopy]; + if (annotation != nil) + [dict setValue:annotation forKey:@"annotation"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"openURL" + object:self + userInfo:dict]; + BOOL handled = ((NSNumber *)dict[@"handled"][@"value"]).boolValue; + return handled; +} @end diff --git a/sky/tools/gn b/sky/tools/gn index 57cf713b253..20453678f97 100755 --- a/sky/tools/gn +++ b/sky/tools/gn @@ -97,6 +97,7 @@ def to_gn_args(args): gn_args['enable_firebase'] = args.enable_firebase gn_args['enable_gcm'] = args.enable_gcm + gn_args['enable_google_sign_in'] = args.enable_google_sign_in gn_args['use_glfw'] = args.use_glfw return gn_args @@ -126,6 +127,7 @@ def parse_args(args): parser.add_argument('--enable-firebase', action='store_true', default=False) parser.add_argument('--enable-gcm', action='store_true', default=False) + parser.add_argument('--enable-google-sign-in', action='store_true', default=False) parser.add_argument('--use-glfw', action='store_true', default=False) return parser.parse_args(args)