Skip to content

Commit

Permalink
Merge pull request #1 from Sayegh7/feature/ios
Browse files Browse the repository at this point in the history
🍏 Adding iOS support
  • Loading branch information
Sayegh7 authored Jul 24, 2019
2 parents c9e0665 + 9166979 commit 3480983
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

.packages
.pub/

build/
*.log
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0

- Add iOS support.

## 0.1.2

- Update Docs.
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 37 additions & 32 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -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<MyApp> {
@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'),
),
),
),
);
}
}
```
22 changes: 22 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
67 changes: 66 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -41,9 +42,12 @@
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
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 = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
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 = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
Expand All @@ -53,6 +57,7 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -62,6 +67,7 @@
files = (
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
15C4E73D78C3283DA3C2E88B /* libPods-Runner.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -87,7 +93,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
CF3B75C9A7D2FA2A4C99F110 /* Frameworks */,
9CFDA919724E469F50F648C5 /* Pods */,
B7FCC614F5D15C5248A15161 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -123,19 +130,40 @@
name = "Supporting Files";
sourceTree = "<group>";
};
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 = "<group>";
};
B7FCC614F5D15C5248A15161 /* Frameworks */ = {
isa = PBXGroup;
children = (
47E09AE508E95BF6F5657807 /* libPods-Runner.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
97C146ED1CF9000F007C117D /* Runner */ = {
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 = (
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions example/ios/Runner.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.2"
version: "0.2.0"
path:
dependency: transitive
description:
Expand Down
5 changes: 3 additions & 2 deletions ios/Classes/MoveToBackgroundPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)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);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/move_to_background.dart
Original file line number Diff line number Diff line change
@@ -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<void> moveTaskToBack() async {
await _channel.invokeMethod('moveTaskToBack');
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <ahmedelsayegh7@gmail.com>

Expand Down

0 comments on commit 3480983

Please sign in to comment.