Skip to content

Instantly share code, notes, and snippets.

@daohoangson
Created September 5, 2019 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daohoangson/e8e878942153af21ec2717e83f146471 to your computer and use it in GitHub Desktop.
Save daohoangson/e8e878942153af21ec2717e83f146471 to your computer and use it in GitHub Desktop.
Xử lý `data` message từ FCM khi app Flutter không chạy
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="xxx">
<!-- ... -->
<application>
<!-- ... -->
<service android:name=".FcmService" android:exported="false">
<!-- priority >0 để đè lên service của firebase_messaging -->
<!-- https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/android/src/main/AndroidManifest.xml -->
<intent-filter android:priority="1">
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// cần làm gì thì xử lý ở đây, xong xuôi nhớ gọi super để plugin chạy tiếp
NSString *foo = [userInfo objectForKey:@"foo"];
return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
public class FcmService extends FlutterFirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// gọi super để plugin làm việc của nó
super.onMessageReceived(remoteMessage);
// cần làm gì thì xử lý ở đây
final Map<String, String> data = remoteMessage.getData();
final String foo = data.get("foo");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment