Skip to content

Commit 24c13e9

Browse files
committed
Merge branch 'feature/custom-app-delegate'
2 parents 5efcaaa + ae70c83 commit 24c13e9

File tree

6 files changed

+65
-51
lines changed

6 files changed

+65
-51
lines changed

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,4 @@ SPEC CHECKSUMS:
120120

121121
PODFILE CHECKSUM: 26b6dfe6bd7b68e4ed6d22322d27708fcee945b0
122122

123-
COCOAPODS: 1.11.3
123+
COCOAPODS: 1.12.0

example/lib/main.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:courier_flutter/ios_foreground_notification_presentation_options
33
import 'package:courier_flutter_sample/env.dart';
44
import 'package:firebase_core/firebase_core.dart';
55
import 'package:firebase_messaging/firebase_messaging.dart';
6-
import 'package:flutter/foundation.dart';
76
import 'package:flutter/material.dart';
87
import 'dart:async';
98

@@ -53,10 +52,7 @@ StreamController<dynamic> pushClicked = StreamController<dynamic>();
5352
class _MyAppState extends State<MyApp> {
5453
bool _isLoading = true;
5554
String? _currentUserId;
56-
final List<CourierProvider> _providers = [
57-
CourierProvider.apns,
58-
CourierProvider.fcm
59-
];
55+
final List<CourierProvider> _providers = [CourierProvider.apns, CourierProvider.fcm];
6056

6157
@override
6258
void initState() {
@@ -102,12 +98,10 @@ class _MyAppState extends State<MyApp> {
10298
final userId = await Courier.shared.userId;
10399
print(userId);
104100

105-
final fetchStatus =
106-
await Courier.shared.getNotificationPermissionStatus();
101+
final fetchStatus = await Courier.shared.getNotificationPermissionStatus();
107102
print(fetchStatus);
108103

109-
final requestStatus =
110-
await Courier.shared.requestNotificationPermission();
104+
final requestStatus = await Courier.shared.requestNotificationPermission();
111105
print(requestStatus);
112106

113107
// Set the current FCM token

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ packages:
4242
path: ".."
4343
relative: true
4444
source: path
45-
version: "1.0.2"
45+
version: "1.0.3"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:

lib/courier_flutter.dart

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ class Courier {
1313
isDebugging = kDebugMode;
1414

1515
// Set the default iOS presentation options
16-
iOSForegroundNotificationPresentationOptions =
17-
_iOSForegroundNotificationPresentationOptions;
16+
iOSForegroundNotificationPresentationOptions = _iOSForegroundNotificationPresentationOptions;
1817

1918
// Register listeners for when the native system receives messages
2019
CourierFlutterEventsPlatform.instance.registerMessagingListeners(
21-
onPushNotificationDelivered: (message) =>
22-
_onPushNotificationDelivered?.call(message),
23-
onPushNotificationClicked: (message) =>
24-
_onPushNotificationClicked?.call(message),
25-
onLogPosted: (log) =>
26-
{/* Empty for now. Flutter will automatically print to console */},
20+
onPushNotificationDelivered: (message) => _onPushNotificationDelivered?.call(message),
21+
onPushNotificationClicked: (message) => _onPushNotificationClicked?.call(message),
22+
onLogPosted: (log) => {
23+
/* Empty for now. Flutter will automatically print to console */
24+
},
2725
);
2826
}
2927

3028
// Singleton
3129
static Courier? _instance;
30+
3231
static Courier get shared => _instance ??= Courier._();
3332

3433
/// Called if set and a push notification is delivered while the app
3534
/// Is in the foreground on iOS and "background" / foreground on Android
3635
Function(dynamic message)? _onPushNotificationDelivered;
36+
3737
set onPushNotificationDelivered(Function(dynamic message)? listener) {
3838
_onPushNotificationDelivered = listener;
3939
}
@@ -42,6 +42,7 @@ class Courier {
4242
/// Will automatically get called the first time your app starts
4343
/// and the user clicked on a push notification to launch your app
4444
Function(dynamic message)? _onPushNotificationClicked;
45+
4546
set onPushNotificationClicked(Function(dynamic message)? listener) {
4647
_onPushNotificationClicked = listener;
4748
CourierFlutterEventsPlatform.instance.getClickedNotification();
@@ -50,7 +51,9 @@ class Courier {
5051
/// Allows you to show or hide Courier Native SDK debugging logs
5152
/// You likely want this to match your development environment debugging mode
5253
bool _isDebugging = kDebugMode;
54+
5355
bool get isDebugging => _isDebugging;
56+
5457
set isDebugging(bool isDebugging) {
5558
CourierFlutterCorePlatform.instance.isDebugging(isDebugging);
5659
_isDebugging = isDebugging;
@@ -60,16 +63,12 @@ class Courier {
6063
/// showing a push notification when it is received while the app is in the foreground.
6164
/// This will not have an affect on any other platform
6265
/// If you do not not want a system push to appear, pass []
66+
List<iOSNotificationPresentationOption> _iOSForegroundNotificationPresentationOptions = iOSNotificationPresentationOption.values;
67+
6368
List<iOSNotificationPresentationOption>
64-
_iOSForegroundNotificationPresentationOptions =
65-
iOSNotificationPresentationOption.values;
66-
List<iOSNotificationPresentationOption>
67-
get iOSForegroundNotificationPresentationOptions =>
68-
_iOSForegroundNotificationPresentationOptions;
69-
set iOSForegroundNotificationPresentationOptions(
70-
List<iOSNotificationPresentationOption> options) {
71-
CourierFlutterEventsPlatform.instance
72-
.iOSForegroundPresentationOptions(options);
69+
get iOSForegroundNotificationPresentationOptions => _iOSForegroundNotificationPresentationOptions;
70+
set iOSForegroundNotificationPresentationOptions(List<iOSNotificationPresentationOption> options) {
71+
CourierFlutterEventsPlatform.instance.iOSForegroundPresentationOptions(options);
7372
_iOSForegroundNotificationPresentationOptions = options;
7473
}
7574

@@ -79,14 +78,12 @@ class Courier {
7978
/// Returns the currently stored apns token in the native SDK
8079
/// If you sign out, this value may still be set so that you can
8180
/// pass it to the next signed in userId
82-
Future<String?> get apnsToken =>
83-
CourierFlutterCorePlatform.instance.apnsToken();
81+
Future<String?> get apnsToken => CourierFlutterCorePlatform.instance.apnsToken();
8482

8583
/// Returns the currently stored fcm token in the native SDK
8684
/// If you sign out, this value may still be set so that you can
8785
/// pass it to the next signed in userId
88-
Future<String?> get fcmToken =>
89-
CourierFlutterCorePlatform.instance.fcmToken();
86+
Future<String?> get fcmToken => CourierFlutterCorePlatform.instance.fcmToken();
9087

9188
/// Sets the current FCM token in Courier Token Management
9289
/// Mostly used for handling the iOS Firebase SDK
@@ -114,29 +111,29 @@ class Courier {
114111
/// You should call this where it makes the most sense for the user experience you are building
115112
/// Android does NOT support this feature yet due to Android AppCompatActivity limitations
116113
Future<NotificationPermissionStatus> requestNotificationPermission() async {
117-
final status = await CourierFlutterEventsPlatform.instance
118-
.requestNotificationPermission();
114+
final status = await CourierFlutterEventsPlatform.instance.requestNotificationPermission();
119115
return status.permissionStatus;
120116
}
121117

122118
/// Returns the current push notification permission status
123119
/// Does not present a popup dialog to your user
124120
Future<NotificationPermissionStatus> getNotificationPermissionStatus() async {
125-
final status = await CourierFlutterEventsPlatform.instance
126-
.getNotificationPermissionStatus();
121+
final status = await CourierFlutterEventsPlatform.instance.getNotificationPermissionStatus();
127122
return status.permissionStatus;
128123
}
129124

130125
/// Sends a push notification to the provider your would like
131126
/// This is used to test your integration
132127
/// For more info: https://www.courier.com/docs/reference/send/message/
133-
Future<String> sendPush(
134-
{required String authKey,
135-
required String userId,
136-
required String title,
137-
required String body,
138-
required List<CourierProvider> providers}) {
139-
return CourierFlutterCorePlatform.instance
140-
.sendPush(authKey, userId, title, body, providers);
128+
Future<String> sendPush({required String authKey, required String userId, required String title, required String body, required List<CourierProvider> providers}) {
129+
return CourierFlutterCorePlatform.instance.sendPush(authKey, userId, title, body, providers);
141130
}
131+
132+
/// Show a log to the console
133+
static void log(String message) {
134+
if (Courier.shared._isDebugging) {
135+
print(message);
136+
}
137+
}
138+
142139
}

lib/courier_flutter_events_method_channel.dart

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:io';
22

3+
import 'package:courier_flutter/courier_flutter.dart';
34
import 'package:courier_flutter/courier_flutter_events_platform_interface.dart';
45
import 'package:flutter/foundation.dart';
56
import 'package:flutter/services.dart';
@@ -14,17 +15,35 @@ class EventsChannelCourierFlutter extends CourierFlutterEventsPlatform {
1415

1516
@override
1617
Future<String> requestNotificationPermission() async {
17-
return await channel.invokeMethod('requestNotificationPermission');
18+
19+
try {
20+
return await channel.invokeMethod('requestNotificationPermission');
21+
} catch (error) {
22+
return 'unknown';
23+
}
24+
1825
}
1926

2027
@override
2128
Future<String> getNotificationPermissionStatus() async {
22-
return await channel.invokeMethod('getNotificationPermissionStatus');
29+
30+
try {
31+
return await channel.invokeMethod('getNotificationPermissionStatus');
32+
} catch (error) {
33+
return 'unknown';
34+
}
35+
2336
}
2437

2538
@override
2639
Future getClickedNotification() async {
27-
return await channel.invokeMethod('getClickedNotification');
40+
41+
try {
42+
return await channel.invokeMethod('getClickedNotification');
43+
} catch (error) {
44+
return;
45+
}
46+
2847
}
2948

3049
@override
@@ -33,9 +52,13 @@ class EventsChannelCourierFlutter extends CourierFlutterEventsPlatform {
3352
// Skip other platforms. Do not show error
3453
if (!Platform.isIOS) return;
3554

36-
return await channel.invokeMethod('iOSForegroundPresentationOptions', {
37-
'options': options.map((option) => option.value).toList(),
38-
});
55+
try {
56+
return await channel.invokeMethod('iOSForegroundPresentationOptions', {
57+
'options': options.map((option) => option.value).toList(),
58+
});
59+
} catch (error) {
60+
return [];
61+
}
3962

4063
}
4164

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: courier_flutter
22
description: The best way to add push notifications to your Flutter app!
3-
version: 1.0.3
3+
version: 1.0.4
44
homepage: https://courier.com
55

66
environment:

0 commit comments

Comments
 (0)