Skip to content

Commit

Permalink
[firebase_messaging] Enable compatibility with other notification plu…
Browse files Browse the repository at this point in the history
…gins (firebase#1829)
  • Loading branch information
MaikuB authored Mar 18, 2020
1 parent 4fc67dd commit 3fc3ca8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
11 changes: 11 additions & 0 deletions packages/firebase_messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 6.0.13

* Implement `UNUserNotificationCenterDelegate` methods to allow plugin to work when method swizzling is disabled.
* Applications now only need to update their iOS project's `AppDelegate` when method swizzling is disabled.
* Applications that need to use `firebase_messaging` with other notification plugins will need to
add the following to their iOS project's `Info.plist` file:
```xml
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
```

## 6.0.12

* Replace deprecated `getFlutterEngine` call on Android.
Expand Down
9 changes: 8 additions & 1 deletion packages/firebase_messaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ To integrate your plugin into the iOS part of your app, follow these steps:

1. Follow the steps in the "[Upload your APNs certificate](https://firebase.google.com/docs/cloud-messaging/ios/client#upload_your_apns_certificate)" section of the Firebase docs.

1. Add the following lines to the `(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions`
1. If you need to disable the method swizzling done by the FCM iOS SDK (e.g. so that you can use this plugin with other notification plugins) then add the following to your application's `Info.plist` file.

```xml
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
```

After that, add the following lines to the `(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions`
method in the `AppDelegate.m`/`AppDelegate.swift` of your iOS project.

Objective-C:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import "Firebase/Firebase.h"

NSString *const kGCMMessageIDKey = @"gcm.message_id";

#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@interface FLTFirebaseMessagingPlugin () <FIRMessagingDelegate>
@end
Expand Down Expand Up @@ -139,7 +141,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
} else if ([@"configure" isEqualToString:method]) {
[FIRMessaging messaging].shouldEstablishDirectChannel = true;
[[UIApplication sharedApplication] registerForRemoteNotifications];
if (_launchNotification != nil) {
if (_launchNotification != nil && _launchNotification[kGCMMessageIDKey]) {
[_channel invokeMethod:@"onLaunch" arguments:_launchNotification];
}
result(nil);
Expand Down Expand Up @@ -189,10 +191,39 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
}

#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// Receive data message on iOS 10 devices while app is in the foreground.
// Received data message on iOS 10 devices while app is in the foreground.
// Only invoked if method swizzling is enabled.
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
[self didReceiveRemoteNotification:remoteMessage.appData];
}

// Received data message on iOS 10 devices while app is in the foreground.
// Only invoked if method swizzling is disabled and UNUserNotificationCenterDelegate has been
// registered in AppDelegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
NS_AVAILABLE_IOS(10.0) {
NSDictionary *userInfo = notification.request.content.userInfo;
// Check to key to ensure we only handle messages from Firebase
if (userInfo[kGCMMessageIDKey]) {
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
[_channel invokeMethod:@"onMessage" arguments:userInfo];
completionHandler(UNNotificationPresentationOptionNone);
}
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler NS_AVAILABLE_IOS(10.0) {
NSDictionary *userInfo = response.notification.request.content.userInfo;
// Check to key to ensure we only handle messages from Firebase
if (userInfo[kGCMMessageIDKey]) {
[_channel invokeMethod:@"onResume" arguments:userInfo];
completionHandler();
}
}

#endif

- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_messaging/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: firebase_messaging
description: Flutter plugin for Firebase Cloud Messaging, a cross-platform
messaging solution that lets you reliably deliver messages on Android and iOS.
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging
version: 6.0.12
version: 6.0.13

flutter:
plugin:
Expand Down

0 comments on commit 3fc3ca8

Please sign in to comment.