Created
September 5, 2019 08:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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