diff --git a/packages/flutter_tools/lib/src/commands/ios.dart b/packages/flutter_tools/lib/src/commands/ios.dart index d5661658ed..5348b53111 100644 --- a/packages/flutter_tools/lib/src/commands/ios.dart +++ b/packages/flutter_tools/lib/src/commands/ios.dart @@ -93,6 +93,41 @@ class IOSCommand extends FlutterCommand { return true; } + + void _writeUserEditableFilesIfNecessary(String directory) { + printStatus("Checking if user editable files need updates"); + + // Step 1: Check if the Info.plist exists and write one if not + File infoPlist = new File(path.join(directory, "Info.plist")); + if (!infoPlist.existsSync()) { + printStatus("Did not find an existing Info.plist. Creating one."); + infoPlist.writeAsStringSync(_infoPlistInitialContents); + } else { + printStatus("Info.plist present. Using existing."); + } + + // Step 2: Check if the LaunchScreen.storyboard exists and write one if not + File launchScreen = new File(path.join(directory, "LaunchScreen.storyboard")); + if (!launchScreen.existsSync()) { + printStatus("Did not find an existing LaunchScreen.storyboard. Creating one."); + launchScreen.writeAsStringSync(_launchScreenInitialContents); + } else { + printStatus("LaunchScreen.storyboard present. Using existing."); + } + + // Step 3: Check if the Assets.xcassets exists and write one if not + Directory xcassets = new Directory(path.join(directory, "Assets.xcassets")); + if (!xcassets.existsSync()) { + printStatus("Did not find an existing Assets.xcassets. Creating one."); + Directory iconsAssetsDir = new Directory(path.join(xcassets.path, "AppIcon.appiconset")); + iconsAssetsDir.createSync(recursive: true); + File iconContents = new File(path.join(iconsAssetsDir.path, "Contents.json")); + iconContents.writeAsStringSync(_iconAssetInitialContents); + } else { + printStatus("Assets.xcassets present. Using existing."); + } + } + void _setupXcodeProjXcconfig(String filePath) { StringBuffer localsBuffer = new StringBuffer(); @@ -116,7 +151,8 @@ class IOSCommand extends FlutterCommand { Future _runInitCommand() async { // Step 1: Fetch the archive from the cloud - String xcodeprojPath = path.join(Directory.current.path, "ios", "Generated"); + String iosFilesPath = path.join(Directory.current.path, "ios"); + String xcodeprojPath = path.join(iosFilesPath, "Generated"); List archiveBytes = await _fetchXcodeArchive(); if (archiveBytes.isEmpty) { @@ -131,6 +167,10 @@ class IOSCommand extends FlutterCommand { return 1; } + // Step 3: Setup default user editable files if this is the first run of + // the init command. + _writeUserEditableFilesIfNecessary(iosFilesPath); + // Step 3: Populate the Local.xcconfig with project specific paths _setupXcodeProjXcconfig(path.join(xcodeprojPath, "Local.xcconfig")); @@ -159,3 +199,159 @@ class IOSCommand extends FlutterCommand { return 1; } } + +final String _infoPlistInitialContents = ''' + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + Runner + CFBundleIdentifier + io.flutter.runner.Runner + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Flutter + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + + +'''; + +final String _launchScreenInitialContents = ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + +'''; + +final String _iconAssetInitialContents = ''' +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} +''';