#android #ios #flutter
#Android #iOS #flutter
Вопрос:
Я хочу перейти на страницу «Входящие» при нажатии на уведомление. Я обрабатываю уведомления в собственном коде. Я хочу сделать это при нажатии на уведомление. Navigator.pushNamed(context,'/inboxPage')
Android Native
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT)
val channelId = getString(R.string.default_notification_channel_id)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.app_icon)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
IOS Native
let notificationContent = UNMutableNotificationContent()
notificationContent.title = userInfo["title"] as! String
notificationContent.body = userInfo["body"] as! String
notificationContent.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: UUID.init().uuidString, content: notificationContent, trigger: nil)
let center = UNUserNotificationCenter.current()
center.add(request) { (error: Error?) in
if let theError = error {
print("error (theError)")
}
}
Комментарии:
1. да, вполне возможно
2. Да, вы можете создать свой собственный канал платформы и сделать это
Ответ №1:
определите глобальную переменную для функции прослушивателя
Function kNotificationClicked;
создать экземпляр / инициализировать метод channel
const platform = MethodChannel('com.myapp.etc');
platform.setMethodCallHandler((call) async {
if (call.method.compareTo('notification-clicked') == 0) {
if(kNotificationClicked!=null){
kNotificationClicked(call.arguments);
}
}
});
в любом виджете (в основном при инициализации или даже лучше при инициализации приложения) установите обратный вызов
kNotificationClicked = (args){
//go to the route
}
на собственной стороне (kotlin) создать экземпляр метода channel
private val CHANNEL = "com.myapp.etc"
protected lateinit var platform: MethodChannel;
fun configureFEngine() {
platform = MethodChannel(flutterView, CHANNEL)
platform.setMethodCallHandler { call, result ->
}
}
вызывайте, когда хотите
fun notificationClicked() {
platform.invokeMethod("notification-clicked", args)
}
Я не тестировал код, но показал вам, как бы я подошел к этому