Flutter 颤振局部通知不';我不为iOS工作

Flutter 颤振局部通知不';我不为iOS工作,flutter,notifications,Flutter,Notifications,你好,这里的新手!我正在使用flatter本地通知,并将默认代码添加到我的应用程序中。它在安卓系统中工作,但在iOS系统中不工作。知道为什么吗 我尝试了iPhone8和iPhone11的iOS模拟器。它在我的android仿真器上工作,它是一个Pixel3API29 我还为此应用启用了iOS中的通知(设置>此应用>通知),并授予了权限 对于Android,我在AndroidManifest.xml中添加了权限请求 import 'package:flutter/material.dart'; i

你好,这里的新手!我正在使用flatter本地通知,并将默认代码添加到我的应用程序中。它在安卓系统中工作,但在iOS系统中不工作。知道为什么吗

我尝试了iPhone8和iPhone11的iOS模拟器。它在我的android仿真器上工作,它是一个Pixel3API29

我还为此应用启用了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 {
    debugPrint("payload : $payload");
    showDialog(
      context: context,
      builder: (_) {
        return AlertDialog(
          title: Text("PayLoad"),
          content: Text("Payload : $payload"),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
              child: Text('Notification'),
              onPressed: _showNotificationWithDefaultSound,
            ),
            FlatButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text('back'),
            )
          ],
        ),
      ),
    );
  }

  // TODO iOS doesn't work

  Future _showNotificationWithDefaultSound() async {
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
        'your channel id', 'your channel name', 'your channel description',
        importance: Importance.Max, priority: Priority.High);
    var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(
      0,
      'New Post',
      'How to Show Notification in Flutter',
      platformChannelSpecifics,
      payload: 'Default_Sound',
    );
  }
导入“包装:颤振/材料.省道”;
导入“package:flatter_local_notifications/flatter_local_notifications.dart”;
类AppNotification扩展了StatefulWidget{
静态常量字符串id='app_notification';
@凌驾
_AppNotificationState createState()=>\u AppNotificationState();
}
类AppNotificationState扩展了状态{
flatterlocalnotificationsplugin flatterlocalnotificationsplugin;
@凌驾
void initState(){
super.initState();
FlatterLocalNotificationsPlugin=FlatterLocalNotificationsPlugin();
var android=AndroidInitializationSettings(“应用程序图标”);
var iOS=IOSInitializationSettings();
var initSettings=初始化设置(android、iOS);
flatterLocalNotificationsPlugin.initialize(初始化设置,
onSelectNotification:onSelectNotification);
}
未来onSelectNotification(字符串负载)异步{
debugPrint(“有效载荷:$payload”);
显示对话框(
上下文:上下文,
建筑商:(){
返回警报对话框(
标题:文本(“有效载荷”),
内容:文本(“有效载荷:$Payload”),
);
},
);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
扁平按钮(
子项:文本(“通知”),
按下时:\显示带有默认声音的通知,
),
扁平按钮(
已按下:(){
Navigator.pop(上下文);
},
子项:文本('back'),
)
],
),
),
);
}
//TODO iOS不起作用
Future\u showNotificationWithDefaultSound()异步{
var androidPlatformChannelSpecifics=新的AndroidNotificationDetails(
“您的频道id”、“您的频道名称”、“您的频道描述”,
重要性:重要性。最大,优先级:优先级。高);
var iOSPlatformChannelSpecifics=新的IOSNotificationDetails();
var platformChannelSpecifics=新通知详细信息(
androidPlatformChannelSpecifics、iOSPlatformChannelSpecifics);
等待本地通知。显示(
0,
"新职位",,
“如何在颤振中显示通知”,
平台通道细节,
有效负载:“默认声音”,
);
}
我在didFinishLaunchingWithOptions方法中的“AppDelegate.swift”中添加了这一行,它解决了我的问题:

if#可用(iOS 10.0,*){
UNUserNotificationCenter.current().delegate=自身为?UNUserNotificationCenterDelegate
}
文档链接:

// 我在插件的文档中找到了这个,希望如此
它解决了你的问题!

嘿,我在iOS上也遇到了同样的问题,当我点击一个按钮时,什么都没有发生。你找到解决方案了吗?这解决了我的问题,谢谢你,这是@fixatd的链接,你能完整地把这个方法放在这里吗?这是我的解决方案,谢谢@K-Soliman