Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Critical Alert #103

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,21 +28,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand Down Expand Up @@ -70,7 +63,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -138,7 +131,7 @@ packages:
path: "../flutter_apns"
relative: true
source: path
version: "1.5.4"
version: "1.6.0"
flutter_apns_only:
dependency: transitive
description:
Expand Down Expand Up @@ -190,28 +183,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -300,7 +293,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -321,21 +314,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
timezone:
dependency: transitive
description:
Expand Down
10 changes: 10 additions & 0 deletions flutter_apns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ If only care about apns - use flutter_apns_only plugin. It does not depend on fi
<true/>
```

## Critical Alert
For use iOS Critical alert request entitlement to Apple throught this form:
[https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/](https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/)

After that assign CriticalAlert capability to your app identifier, update provisioning profiles and add this entry to app `.entitlements` file in your code:
```
<key>com.apple.developer.usernotifications.critical-alerts</key>
<true/>
```

## Troubleshooting

1. Ensure that you are testing on actual device. NOTE: this may not be needed from 11.4: https://ohmyswift.com/blog/2020/02/13/simulating-remote-push-notifications-in-a-simulator/
Expand Down
31 changes: 12 additions & 19 deletions flutter_apns/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,21 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand All @@ -49,7 +42,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
firebase_core:
dependency: "direct main"
description:
Expand Down Expand Up @@ -127,28 +120,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -167,7 +160,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -188,21 +181,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
vector_math:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion flutter_apns/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
sdk: flutter
firebase_core: ^1.20.0
firebase_messaging: ^12.0.1
flutter_apns_only: ^1.5.2
flutter_apns_only: ^1.6.1

dev_dependencies:
flutter_test:
Expand Down
9 changes: 8 additions & 1 deletion flutter_apns_only/ios/Classes/FlutterApnsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func getFlutterError(_ error: Error) -> FlutterError {

var provisionalRequested = false
if #available(iOS 12.0, *) {
if readBool("criticalAlert") {
options.append(.criticalAlert)
}
if readBool("provisional") {
options.append(.provisional)
provisionalRequested = true
Expand All @@ -145,12 +148,16 @@ func getFlutterError(_ error: Error) -> FlutterError {
}

center.getNotificationSettings { (settings) in
let map = [
var map = [
"sound": settings.soundSetting == .enabled,
"badge": settings.badgeSetting == .enabled,
"alert": settings.alertSetting == .enabled,
"provisional": granted && provisionalRequested
]

if #available(iOS 12.0, *) {
map["criticalAlert"] = settings.criticalAlertSetting == .enabled
}

self.channel.invokeMethod("onIosSettingsRegistered", arguments: map)
}
Expand Down
27 changes: 18 additions & 9 deletions flutter_apns_only/lib/flutter_apns_only.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ class ApnsPushConnectorOnly {
ApnsMessageHandler? _onResume;

Future<bool> requestNotificationPermissions(
[IosNotificationSettings iosSettings = const IosNotificationSettings()]) async {
[IosNotificationSettings iosSettings =
const IosNotificationSettings()]) async {
final bool? result = await _channel.invokeMethod<bool>(
'requestNotificationPermissions', iosSettings.toMap());
return result ?? false;
}

Future<ApnsAuthorizationStatus> getAuthorizationStatus() async {
return _authorizationStatusForString(await _channel.invokeMethod<String?>('getAuthorizationStatus', []));
return _authorizationStatusForString(
await _channel.invokeMethod<String?>('getAuthorizationStatus', []));
}

final StreamController<IosNotificationSettings> _iosSettingsStreamController =
Expand Down Expand Up @@ -142,23 +144,30 @@ class ApnsPushConnectorOnly {
}

class IosNotificationSettings {
const IosNotificationSettings({
this.sound = true,
this.alert = true,
this.badge = true,
});
const IosNotificationSettings(
{this.sound = true,
this.alert = true,
this.badge = true,
this.criticalAlert = false});

IosNotificationSettings._fromMap(Map<String, bool> settings)
: sound = settings['sound'],
alert = settings['alert'],
badge = settings['badge'];
badge = settings['badge'],
criticalAlert = settings['criticalAlert'];

final bool? sound;
final bool? alert;
final bool? badge;
final bool? criticalAlert;

Map<String, dynamic> toMap() {
return <String, bool?>{'sound': sound, 'alert': alert, 'badge': badge};
return <String, bool?>{
'sound': sound,
'alert': alert,
'badge': badge,
'criticalAlert': criticalAlert
};
}

@override
Expand Down
Loading