diff --git a/.gitignore b/.gitignore index e9dc58d..c1f76e8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ .packages .pub/ - build/ +*.log diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b2799..8413285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.0 + +- Add iOS support. + ## 0.1.2 - Update Docs. diff --git a/README.md b/README.md index e6554b2..897ea12 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # move_to_background -Flutter plugin for sending android application to background. Note that currently only android is supported. +Flutter plugin for sending mobile applications to background. Supports iOS and Android. ## Getting Started ### Install it (pubspec.yaml) ```yaml -move_to_background: ^0.1.2 +move_to_background: ^0.2.0 ``` ### Import it @@ -35,3 +35,7 @@ WillPopScope( }, ); ``` + +## Note about using it for iOS + +Quitting your application or sending it to the background programmatically is a violation of the iOS [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/overview/themes/#//apple_ref/doc/uid/TP40006556-CH20-SW27), which usually doesn't bode well for getting through the review process. Keep that in mind. diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml index 39c65f6..d5d35ec 100644 --- a/android/.idea/misc.xml +++ b/android/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/android/.idea/vcs.xml b/android/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/android/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/example/README.md b/example/README.md index e6554b2..f76ac1c 100644 --- a/example/README.md +++ b/example/README.md @@ -1,37 +1,42 @@ -# move_to_background - -Flutter plugin for sending android application to background. Note that currently only android is supported. - -## Getting Started - -### Install it (pubspec.yaml) - -```yaml -move_to_background: ^0.1.2 -``` - -### Import it +# Example App ```dart -import 'package:move_to_background/move_to_background.dart'; -``` +import 'package:flutter/material.dart'; -### Use it - -```dart -MoveToBackground.moveTaskToBack(); -``` - -## Useful Scenario - -Use with WillPopScope to send your application to the background when the user attempts to exit the app. +import 'package:move_to_background/move_to_background.dart'; -```dart -WillPopScope( - child: MaterialApp(...), - onWillPop: () async { - MoveToBackground.moveTaskToBack(); - return false; - }, -); +void main() => runApp(MyApp()); + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + Widget build(BuildContext context) { + return WillPopScope( + onWillPop: () async { + MoveToBackground.moveTaskToBack(); + return false; + }, + child: MaterialApp( + home: Scaffold( + floatingActionButton: FloatingActionButton( + child: Icon(Icons.arrow_downward), + onPressed: () { + MoveToBackground.moveTaskToBack(); + }, + ), + appBar: AppBar( + title: const Text('MoveToBackground Example'), + ), + body: Center( + child: Text('Press the floating action button'), + ), + ), + ), + ); + } +} ``` diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock new file mode 100644 index 0000000..c1cfd11 --- /dev/null +++ b/example/ios/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - Flutter (1.0.0) + - move_to_background (0.0.1): + - Flutter + +DEPENDENCIES: + - Flutter (from `.symlinks/flutter/ios`) + - move_to_background (from `.symlinks/plugins/move_to_background/ios`) + +EXTERNAL SOURCES: + Flutter: + :path: ".symlinks/flutter/ios" + move_to_background: + :path: ".symlinks/plugins/move_to_background/ios" + +SPEC CHECKSUMS: + Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a + move_to_background: 39a5b79b26d577b0372cbe8a8c55e7aa9fcd3a2d + +PODFILE CHECKSUM: 7fb83752f59ead6285236625b82473f90b1cb932 + +COCOAPODS: 1.7.5 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 51d12ea..0799f7a 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 15C4E73D78C3283DA3C2E88B /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 47E09AE508E95BF6F5657807 /* libPods-Runner.a */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -41,9 +42,12 @@ 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 = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; + 47E09AE508E95BF6F5657807 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6331110D34E5EBED376233A7 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 8487FA1079DC91CCC63F8599 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; @@ -53,6 +57,7 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + FADAA6B8BD48BD8768461565 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -62,6 +67,7 @@ files = ( 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, + 15C4E73D78C3283DA3C2E88B /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -87,7 +93,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, + 9CFDA919724E469F50F648C5 /* Pods */, + B7FCC614F5D15C5248A15161 /* Frameworks */, ); sourceTree = ""; }; @@ -123,6 +130,25 @@ name = "Supporting Files"; sourceTree = ""; }; + 9CFDA919724E469F50F648C5 /* Pods */ = { + isa = PBXGroup; + children = ( + FADAA6B8BD48BD8768461565 /* Pods-Runner.debug.xcconfig */, + 6331110D34E5EBED376233A7 /* Pods-Runner.release.xcconfig */, + 8487FA1079DC91CCC63F8599 /* Pods-Runner.profile.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; + B7FCC614F5D15C5248A15161 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 47E09AE508E95BF6F5657807 /* libPods-Runner.a */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -130,12 +156,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + 0270BC8B8E54361010B0E7AF /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + D298FAB2D7F99FB3E88324F0 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -194,6 +222,28 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 0270BC8B8E54361010B0E7AF /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -222,6 +272,21 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + D298FAB2D7F99FB3E88324F0 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcworkspace/contents.xcworkspacedata index 1d526a1..21a3cc1 100644 --- a/example/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/example/pubspec.lock b/example/pubspec.lock index c835b35..003d250 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -66,7 +66,7 @@ packages: path: ".." relative: true source: path - version: "0.1.2" + version: "0.2.0" path: dependency: transitive description: diff --git a/ios/Classes/MoveToBackgroundPlugin.m b/ios/Classes/MoveToBackgroundPlugin.m index db91b5d..cfe9c7f 100644 --- a/ios/Classes/MoveToBackgroundPlugin.m +++ b/ios/Classes/MoveToBackgroundPlugin.m @@ -10,8 +10,9 @@ + (void)registerWithRegistrar:(NSObject*)registrar { } - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([@"getPlatformVersion" isEqualToString:call.method]) { - result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); + if ([@"moveTaskToBack" isEqualToString:call.method]) { + UIApplication *app = [UIApplication sharedApplication]; + [app performSelector:@selector(suspend)]; } else { result(FlutterMethodNotImplemented); } diff --git a/lib/move_to_background.dart b/lib/move_to_background.dart index b939895..4a7b435 100644 --- a/lib/move_to_background.dart +++ b/lib/move_to_background.dart @@ -1,11 +1,15 @@ +/// This library is a wrapper for iOS and Android to send the application to the background programmatically. import 'dart:async'; import 'package:flutter/services.dart'; +/// A class containing the static function used. class MoveToBackground { + /// The method channel used to contact the native side static const MethodChannel _channel = const MethodChannel('move_to_background'); + /// Calls the platform-specific function to send the app to the background static Future moveTaskToBack() async { await _channel.invokeMethod('moveTaskToBack'); } diff --git a/pubspec.yaml b/pubspec.yaml index c74c3fd..f434833 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: move_to_background description: Flutter plugin for sending application to background. Send your app to the background with one line of code. -version: 0.1.2 +version: 0.2.0 homepage: https://github.com/Sayegh7/move_to_background author: Ahmed El Sayegh