你好颤振新手在这里!我正在使用颤振本地通知并将默认代码添加到我的应用程序中。它适用于Android,但不适用于iOS。知道为什么吗?
我尝试了 iPhone 8 和 iPhone 11 的 iOS 模拟器。它适用于我的 Pixel 3 API 29 android 模拟器。
我还为此应用程序启用了 iOS 中的通知(设置>此应用程序>通知)并授予权限。
对于 Android,我在 AndroidManifest.xml 中添加了权限请求。
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class AppNotification extends StatefulWidget {
static const String id = 'app_notification';
@override
_AppNotificationState createState() => _AppNotificationState();
}
class _AppNotificationState extends State<AppNotification> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
@override
void initState() {
super.initState();
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
var android = AndroidInitializationSettings('app_icon');
var iOS = IOSInitializationSettings();
var initSettings = InitializationSettings(android, iOS);
flutterLocalNotificationsPlugin.initialize(initSettings,
onSelectNotification: onSelectNotification);
}
Future onSelectNotification(String payload) async …Run Code Online (Sandbox Code Playgroud)