From 9f5311561685bdb06bc92d9d16c6a19c1af5a71c Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 19 Oct 2020 18:18:42 +0200 Subject: [PATCH] ios: Add iCloud capability I cannot see the GitJournal app's data in my iCloud, but I believe maybe my app needs to go through the app review process. --- assets/langs/en.yaml | 1 + ios/Podfile.lock | 6 ++++++ ios/Runner.xcodeproj/project.pbxproj | 6 ++++++ ios/Runner/Info.plist | 12 ++++++++++++ lib/app.dart | 9 +++++---- lib/screens/settings_screen.dart | 22 ++++++++++++++++++++++ lib/state_container.dart | 2 ++ pubspec.lock | 13 +++++++++++-- pubspec.yaml | 2 ++ scripts/build_ios.sh | 1 + 10 files changed, 68 insertions(+), 6 deletions(-) diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml index b103a835..bdc17187 100644 --- a/assets/langs/en.yaml +++ b/assets/langs/en.yaml @@ -135,6 +135,7 @@ settings: title: Storage fileName: Filename useLocal: Store Repo Internally + icloud: Store in iCloud repoLocation: Repo Location drawer: title: Sidebar Settings diff --git a/ios/Podfile.lock b/ios/Podfile.lock index fe80e127..b6b8af75 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -120,6 +120,8 @@ PODS: - GoogleUtilities/Logger - GoogleUtilities/UserDefaults (6.7.2): - GoogleUtilities/Logger + - icloud_documents_path (0.0.1): + - Flutter - image_picker (0.0.1): - Flutter - in_app_purchase (0.0.1): @@ -172,6 +174,7 @@ DEPENDENCIES: - flutter_email_sender (from `.symlinks/plugins/flutter_email_sender/ios`) - flutter_sentry (from `.symlinks/plugins/flutter_sentry/ios`) - flutter_webview_plugin (from `.symlinks/plugins/flutter_webview_plugin/ios`) + - icloud_documents_path (from `.symlinks/plugins/icloud_documents_path/ios`) - image_picker (from `.symlinks/plugins/image_picker/ios`) - in_app_purchase (from `.symlinks/plugins/in_app_purchase/ios`) - launch_review (from `.symlinks/plugins/launch_review/ios`) @@ -229,6 +232,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_sentry/ios" flutter_webview_plugin: :path: ".symlinks/plugins/flutter_webview_plugin/ios" + icloud_documents_path: + :path: ".symlinks/plugins/icloud_documents_path/ios" image_picker: :path: ".symlinks/plugins/image_picker/ios" in_app_purchase: @@ -278,6 +283,7 @@ SPEC CHECKSUMS: GoogleAppMeasurement: 67458367830514fb20fd9e233496f1eef9d90185 GoogleDataTransport: 672fb0ce96fe7f7f31d43672fca62ad2c9c86f7b GoogleUtilities: 7f2f5a07f888cdb145101d6042bc4422f57e70b3 + icloud_documents_path: 11c858abe03d6900cacce4ef86267f527c89ab7d image_picker: 66aa71bc96850a90590a35d4c4a2907b0d823109 in_app_purchase: 3e2155afa9d03d4fa32d9e62d567885080ce97d6 launch_review: 75d5a956ba8eaa493e9c9d4bf4c05e505e8d5ed0 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 03fab9d4..148073f0 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -45,6 +45,7 @@ 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 7A0DAA2D2475DD8D00C0E570 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; + 7A24F7D5253B512A009E06F7 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; 7A2A0C18229C2E3300FE4F1B /* libssl.framework */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libssl.framework; path = libs/libssl.framework; sourceTree = ""; }; 7A2A0C19229C2E3300FE4F1B /* libcrypto.framework */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcrypto.framework; path = libs/libcrypto.framework; sourceTree = ""; }; 7A2A0C1C229FEA4500FE4F1B /* libgit2.framework */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgit2.framework; path = libs/libgit2.framework; sourceTree = ""; }; @@ -148,6 +149,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 7A24F7D5253B512A009E06F7 /* Runner.entitlements */, 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 97C146FA1CF9000F007C117D /* Main.storyboard */, @@ -340,6 +342,7 @@ "${BUILT_PRODUCTS_DIR}/file_picker/file_picker.framework", "${BUILT_PRODUCTS_DIR}/flutter_email_sender/flutter_email_sender.framework", "${BUILT_PRODUCTS_DIR}/flutter_webview_plugin/flutter_webview_plugin.framework", + "${BUILT_PRODUCTS_DIR}/icloud_documents_path/icloud_documents_path.framework", "${BUILT_PRODUCTS_DIR}/image_picker/image_picker.framework", "${BUILT_PRODUCTS_DIR}/in_app_purchase/in_app_purchase.framework", "${BUILT_PRODUCTS_DIR}/launch_review/launch_review.framework", @@ -372,6 +375,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/file_picker.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_email_sender.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_webview_plugin.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/icloud_documents_path.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_picker.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/in_app_purchase.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/launch_review.framework", @@ -540,6 +544,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; @@ -575,6 +580,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 3f99662c..652377fa 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -2,6 +2,18 @@ + NSUbiquitousContainers + + iCloud.io.gitjournal.gitjournal + + NSUbiquitousContainerSupportedFolderLevels + Any + NSUbiquitousContainerName + GitJournal + NSUbiquitousContainerIsDocumentScopePublic + + + LSSupportsOpeningDocumentsInPlace UIFileSharingEnabled diff --git a/lib/app.dart b/lib/app.dart index 3ff0b562..5dc7e517 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -10,6 +10,7 @@ import 'package:dynamic_theme/dynamic_theme.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization_loader/easy_localization_loader.dart'; import 'package:flutter_sentry/flutter_sentry.dart'; +import 'package:icloud_documents_path/icloud_documents_path.dart'; import 'package:package_info/package_info.dart'; import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; @@ -25,19 +26,19 @@ import 'package:gitjournal/iap.dart'; import 'package:gitjournal/screens/filesystem_screen.dart'; import 'package:gitjournal/screens/folder_listing.dart'; import 'package:gitjournal/screens/graph_view.dart'; +import 'package:gitjournal/screens/home_screen.dart'; import 'package:gitjournal/screens/note_editor.dart'; +import 'package:gitjournal/screens/onboarding_screens.dart'; import 'package:gitjournal/screens/purchase_screen.dart'; import 'package:gitjournal/screens/purchase_thankyou_screen.dart'; +import 'package:gitjournal/screens/settings_screen.dart'; import 'package:gitjournal/screens/tag_listing.dart'; import 'package:gitjournal/settings.dart'; +import 'package:gitjournal/setup/screens.dart'; import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/themes.dart'; import 'package:gitjournal/utils.dart'; import 'package:gitjournal/utils/logger.dart'; -import 'screens/home_screen.dart'; -import 'screens/onboarding_screens.dart'; -import 'screens/settings_screen.dart'; -import 'setup/screens.dart'; class JournalApp extends StatefulWidget { final AppState appState; diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index b2b252e6..0c9333ea 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -6,6 +6,7 @@ import 'package:dynamic_theme/dynamic_theme.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:ext_storage/ext_storage.dart'; import 'package:filesystem_picker/filesystem_picker.dart'; +import 'package:icloud_documents_path/icloud_documents_path.dart'; import 'package:path/path.dart' as p; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; @@ -351,6 +352,27 @@ class SettingsListState extends State { subtitle: Text(settings.storageLocation), enabled: !settings.storeInternally, ), + if (Platform.isIOS) + SwitchListTile( + title: Text(tr('settings.storage.icloud')), + value: !settings.storeInternally, + onChanged: (bool newVal) async { + if (newVal == false) { + settings.storeInternally = true; + settings.storageLocation = ""; + } else { + settings.storageLocation = + await ICloudDocumentsPath.documentsPath; + if (settings.storageLocation.isNotEmpty) { + settings.storeInternally = false; + } + } + settings.save(); + stateContainer.moveRepoToPath(); + + setState(() {}); + }, + ), ListTile( title: Text(tr('settings.misc.title')), onTap: () { diff --git a/lib/state_container.dart b/lib/state_container.dart index b9475d71..a936fc4c 100644 --- a/lib/state_container.dart +++ b/lib/state_container.dart @@ -361,6 +361,8 @@ class StateContainer with ChangeNotifier { repoPath = newRepoPath; appState.notesFolder.reset(repoPath); notifyListeners(); + + _loadNotes(); } } } diff --git a/pubspec.lock b/pubspec.lock index 6eef8ef1..f90c4303 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -438,7 +438,7 @@ packages: name: git_bindings url: "https://pub.dartlang.org" source: hosted - version: "0.0.15" + version: "0.0.16" git_url_parse2: dependency: "direct main" description: @@ -481,6 +481,15 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.3" + icloud_documents_path: + dependency: "direct main" + description: + path: "." + ref: HEAD + resolved-ref: "3fcefd4ba6c1897da1d3a67608dd30eeaa71a9b8" + url: "https://github.com/GitJournal/icloud_documents_path.git" + source: git + version: "0.0.1" image: dependency: transitive description: @@ -1155,4 +1164,4 @@ packages: version: "0.0.9" sdks: dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.17.0 <2.0.0" + flutter: ">=1.20.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index d831a93d..c7d0abef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,6 +62,8 @@ dependencies: filesystem_picker: ^1.0.3 # for directories permission_handler: ^5.0.1+1 ext_storage: ^1.0.3 + icloud_documents_path: + git: https://github.com/GitJournal/icloud_documents_path.git dev_dependencies: flutter_launcher_icons: "^0.7.2" diff --git a/scripts/build_ios.sh b/scripts/build_ios.sh index 44e1cbc6..36a59471 100755 --- a/scripts/build_ios.sh +++ b/scripts/build_ios.sh @@ -14,6 +14,7 @@ cd ../ if [[ $(git status -s | grep -v '??') ]]; then echo "Uncommitted Changes." echo "Exiting" + git status exit 1 fi