提交 29c80227 编写于 作者: A Adam Barth

Move main_ios.mm over to public APIs (#2637)

After this patch, main_ios.mm now consumes Flutter.framework via public APIs.
This patch prepares us to move Flutter on iOS over to consuming
Flutter.framework as a binary artifact.
上级 6907cdcf
......@@ -249,14 +249,14 @@ if (is_android) {
source_set(target_name) {
sources = [
"platform/ios/FlutterAppDelegate.h",
"platform/ios/FlutterAppDelegate.mm",
"platform/ios/framework/Headers/Flutter.h",
"platform/ios/framework/Headers/FlutterAppDelegate.h",
"platform/ios/framework/Headers/FlutterDartProject.h",
"platform/ios/framework/Headers/FlutterMacros.h",
"platform/ios/framework/Headers/FlutterViewController.h",
"platform/ios/framework/Source/accessibility_bridge.h",
"platform/ios/framework/Source/accessibility_bridge.mm",
"platform/ios/framework/Source/FlutterAppDelegate.mm",
"platform/ios/framework/Source/FlutterDartProject.mm",
"platform/ios/framework/Source/FlutterDartProject_Internal.h",
"platform/ios/framework/Source/FlutterDartSource.h",
......@@ -378,6 +378,7 @@ if (is_android) {
copy("framework_headers") {
sources = [
"platform/ios/framework/Headers/Flutter.h",
"platform/ios/framework/Headers/FlutterAppDelegate.h",
"platform/ios/framework/Headers/FlutterDartProject.h",
"platform/ios/framework/Headers/FlutterMacros.h",
"platform/ios/framework/Headers/FlutterViewController.h",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FLUTTERAPPDELEGATE_H_
#define FLUTTER_FLUTTERAPPDELEGATE_H_
#import <UIKit/UIKit.h>
#include "FlutterMacros.h"
// A simple app delegate that creates a single full-screen Flutter application.
// Using FlutterAppDelegate is optional. The framework provides this interface
// to make it easy to get started with simple Flutter apps.
FLUTTER_EXPORT
@interface FlutterAppDelegate : UIResponder<UIApplicationDelegate>
@property(strong, nonatomic) UIWindow* window;
@end
#endif // FLUTTER_FLUTTERDARTPROJECT_H_
......@@ -20,6 +20,8 @@ FLUTTER_EXPORT
packages:(NSURL*)dartPackages
NS_DESIGNATED_INITIALIZER;
- (instancetype)initFromDefaultSourceForConfiguration;
@end
#endif // FLUTTER_FLUTTERDARTPROJECT_H_
......@@ -20,4 +20,7 @@ FLUTTER_EXPORT
@end
// Initializes Flutter for this process. Need only be called once per process.
FLUTTER_EXPORT void FlutterInit(int argc, const char* argv[]);
#endif // FLUTTER_FLUTTERVIEWCONTROLLER_H_
......@@ -2,46 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/trace_event/trace_event.h"
#include "sky/shell/platform/ios/FlutterAppDelegate.h"
#include "sky/shell/platform/ios/framework/Headers/FlutterAppDelegate.h"
#include "sky/shell/platform/ios/framework/Headers/FlutterViewController.h"
#include "sky/shell/switches.h"
NSURL* URLForSwitch(const char* name) {
auto cmd = *base::CommandLine::ForCurrentProcess();
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if (cmd.HasSwitch(name)) {
auto url = [NSURL fileURLWithPath:@(cmd.GetSwitchValueASCII(name).c_str())];
[defaults setURL:url forKey:@(name)];
[defaults synchronize];
return url;
}
return [defaults URLForKey:@(name)];
}
@implementation FlutterAppDelegate
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
TRACE_EVENT0("flutter", "applicationDidFinishLaunchingWithOptions");
#if TARGET_IPHONE_SIMULATOR
FlutterDartProject* project = [[FlutterDartProject alloc]
initWithFLXArchive:URLForSwitch(sky::shell::switches::kFLX)
dartMain:URLForSwitch(sky::shell::switches::kMainDartFile)
packages:URLForSwitch(sky::shell::switches::kPackages)];
#else
NSString* bundlePath =
[[NSBundle mainBundle] pathForResource:@"FlutterApplication"
ofType:@"framework"
inDirectory:@"Frameworks"];
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
FlutterDartProject* project =
[[FlutterDartProject alloc] initWithPrecompiledDartBundle:bundle];
#endif
[[FlutterDartProject alloc] initFromDefaultSourceForConfiguration];
CGRect frame = [UIScreen mainScreen].bounds;
UIWindow* window = [[UIWindow alloc] initWithFrame:frame];
......@@ -76,7 +46,7 @@ NSURL* URLForSwitch(const char* name) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"openURL"
object:self
userInfo:dict];
BOOL handled = ((NSNumber *)dict[@"handled"][@"value"]).boolValue;
return handled;
return ((NSNumber *)dict[@"handled"][@"value"]).boolValue;
}
@end
......@@ -3,7 +3,32 @@
// found in the LICENSE file.
#include "sky/shell/platform/ios/framework/Source/FlutterDartProject_Internal.h"
#include "base/command_line.h"
#include "sky/shell/platform/ios/framework/Source/FlutterDartSource.h"
#include "sky/shell/switches.h"
namespace {
#if TARGET_IPHONE_SIMULATOR
NSURL* URLForSwitch(const char* name) {
auto cmd = *base::CommandLine::ForCurrentProcess();
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if (cmd.HasSwitch(name)) {
auto url = [NSURL fileURLWithPath:@(cmd.GetSwitchValueASCII(name).c_str())];
[defaults setURL:url forKey:@(name)];
[defaults synchronize];
return url;
}
return [defaults URLForKey:@(name)];
}
#endif // TARGET_IPHONE_SIMULATOR
} // namespace
@implementation FlutterDartProject {
NSBundle* _precompiledDartBundle;
......@@ -48,6 +73,24 @@
return self;
}
#pragma mark - Convenience initializers
- (instancetype)initFromDefaultSourceForConfiguration {
#if TARGET_IPHONE_SIMULATOR
return [self
initWithFLXArchive:URLForSwitch(sky::shell::switches::kFLX)
dartMain:URLForSwitch(sky::shell::switches::kMainDartFile)
packages:URLForSwitch(sky::shell::switches::kPackages)];
#else
NSString* bundlePath =
[[NSBundle mainBundle] pathForResource:@"FlutterApplication"
ofType:@"framework"
inDirectory:@"Frameworks"];
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
return [self initWithPrecompiledDartBundle:bundle];
#endif
}
#pragma mark - Common initialization tasks
- (void)checkReadiness {
......
......@@ -23,6 +23,12 @@
#include "sky/shell/shell.h"
#include "sky/shell/shell_view.h"
void FlutterInit(int argc, const char* argv[]) {
NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]];
NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"];
sky::shell::PlatformMacMain(argc, argv, icuDataPath.UTF8String);
}
@implementation FlutterViewController {
FlutterDartProject* _dartProject;
UIInterfaceOrientationMask _orientationPreferences;
......@@ -63,17 +69,10 @@
#pragma mark - Common view controller initialization tasks
- (void)performCommonViewControllerInitialization {
if (_initialized) {
if (_initialized)
return;
}
_initialized = YES;
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"];
sky::shell::PlatformMacMain(0, nullptr, icuDataPath.UTF8String);
_orientationPreferences = UIInterfaceOrientationMaskAll;
_dynamicServiceLoader = [[FlutterDynamicServiceLoader alloc] init];
_viewportMetrics = sky::ViewportMetrics::New();
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <UIKit/UIKit.h>
#include "sky/shell/platform/ios/FlutterAppDelegate.h"
#include "sky/shell/platform/mac/platform_mac.h"
#include "sky/shell/platform/ios/framework/Headers/FlutterAppDelegate.h"
#include "sky/shell/platform/ios/framework/Headers/FlutterViewController.h"
int main(int argc, const char* argv[]) {
// iOS does use the FlutterViewController that initializes the platform but
// we have the command line args here. So call it now.
sky::shell::PlatformMacMain(argc, argv, "");
FlutterInit(argc, argv);
return UIApplicationMain(argc, (char**)argv, nil,
NSStringFromClass([FlutterAppDelegate class]));
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册