Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
推送通知未正确连接到firebase消息_Firebase_Flutter_Firebase Realtime Database_Firebase Cloud Messaging - Fatal编程技术网

推送通知未正确连接到firebase消息

推送通知未正确连接到firebase消息,firebase,flutter,firebase-realtime-database,firebase-cloud-messaging,Firebase,Flutter,Firebase Realtime Database,Firebase Cloud Messaging,我正在尝试在我的Iphone模拟器上测试推送通知。由于某种原因,我的测试似乎都没有通过。随着firebaseMessaging的新更新,我也无法确定如何正确地将测试通知打印到我的终端,以查看它是否正确连接。我是一个新手,在我的课堂上学习一门非常过时的课程。如果有人能就我可能会犯的错误给出一些建议,我将不胜感激。先谢谢你。下面是我的pushnotification service.dart文件 import 'package:firebase_database/firebase_database.

我正在尝试在我的Iphone模拟器上测试推送通知。由于某种原因,我的测试似乎都没有通过。随着firebaseMessaging的新更新,我也无法确定如何正确地将测试通知打印到我的终端,以查看它是否正确连接。我是一个新手,在我的课堂上学习一门非常过时的课程。如果有人能就我可能会犯的错误给出一些建议,我将不胜感激。先谢谢你。下面是我的pushnotification service.dart文件

import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:driver/datamodels/jobdetails.dart';
import 'package:driver/globalvariables.dart';
import 'dart:io';
import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:driver/widgets/ProgressDialog.dart';

class PushNotificationService {

  final FirebaseMessaging fcm = FirebaseMessaging.instance;

  Future initialize(context) async {
    if (Platform.isIOS) {
      fcm.requestPermission(
        alert: true,
        announcement: false,
        badge: true,
        carPlay: false,
        criticalAlert: false,
        provisional: false,
        sound: true,
      );
    }

    FirebaseMessaging.onMessage.listen((event) {
      // fetchJobInfo(getJobID(message), context);
      (Map<String, dynamic> message) async => fetchJobInfo(getJobID(message), context);
    });

    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      // fetchJobInfo(getJobID(message), context);
      (Map<String, dynamic> message) async => fetchJobInfo(getJobID(message), context);
    });
  }

  Future<String> getToken() async {
    String token = await fcm.getToken();
    print('token: $token');

    DatabaseReference tokenRef = FirebaseDatabase.instance.reference().child('drivers/${currentFirebaseUser.uid}/token');
    tokenRef.set(token);

    fcm.subscribeToTopic('alldrivers');
    fcm.subscribeToTopic('allusers');
  }

  String getJobID(Map<String, dynamic> message){

    String jobID = '';

    if(Platform.isAndroid){
      jobID = message['data']['job_id'];
    }
    else{
      jobID = message['job_id'];
      print('job_id: $jobID');
    }

    return jobID;
  }

  void fetchJobInfo(String jobID, context) {
    //show please wait dialog
    showDialog(
      barrierDismissible: false,
      context: context,
      builder: (BuildContext context) =>
          ProgressDialog(status: 'Fetching Details...',),
    );

    DatabaseReference jobRef = FirebaseDatabase.instance.reference().child(
        'jobRequest/$jobID');
    jobRef.once().then((DataSnapshot snapshot) {
      Navigator.pop(context);

      final assetAudioPlayer = AssetsAudioPlayer();
      if (snapshot.value != null) {
        assetAudioPlayer.open(Audio('sounds/sounds_alert.mp3'));
        assetAudioPlayer.play();

        double destinationLat = double.parse(
            snapshot.value['destination']['latitude'].toString());
        double destinationLng = double.parse(
            snapshot.value['destination']['longitude'].toString());
        String destinationAddress = snapshot.value['destination_address'];
        String paymentMethod = snapshot.value['payment_method'];

        JobDetails jobDetails = JobDetails();

        jobDetails.jobID = jobID;
        jobDetails.destinationAddress = destinationAddress;
        jobDetails.destination = LatLng(destinationLat, destinationLng);
        jobDetails.paymentMethod = paymentMethod;

        // showDialog(
        //     context: context,
        //     barrierDismissible: false,
        //     builder: (BuildContext context) => NotificationDialog(jobDetails: jobDetails,),
        // );
      }
    });
  }
}
 
import'包:firebase_数据库/firebase_数据库.dart';
导入“package:firebase_messaging/firebase_messaging.dart”;
进口“包装:颤振/cupertino.dart”;
进口“包装:颤振/材料.省道”;
导入“包:google_-maps_-flatter/google_-maps_-flatter.dart”;
导入“包:driver/datamodels/jobdetails.dart”;
导入“包:驱动程序/globalvariables.dart”;
导入“dart:io”;
导入“package:assets_audio_player/assets_audio_player.dart”;
导入“package:driver/widgets/ProgressDialog.dart”;
类PushNotificationService{
final FirebaseMessaging fcm=FirebaseMessaging.instance;
未来初始化(上下文)异步{
if(Platform.isIOS){
fcm.requestPermission(
警报:是的,
公告:假,,
徽章:没错,
carPlay:错,
评论家:错,
暂定:假,
听起来:是的,
);
}
FirebaseMessaging.onMessage.listen((事件){
//fetchJobInfo(getJobID(消息),上下文);
(映射消息)async=>fetchJobInfo(getJobID(消息),上下文);
});
FirebaseMessaging.onMessageGeoPenedApp.listen((远程消息){
//fetchJobInfo(getJobID(消息),上下文);
(映射消息)async=>fetchJobInfo(getJobID(消息),上下文);
});
}
Future getToken()异步{
String token=wait fcm.getToken();
打印('token:$token');
DatabaseReference tokenRef=FirebaseDatabase.instance.reference().child('drivers/${currentFirebaseUser.uid}/token');
tokenRef.set(令牌);
fcm.订阅主题(“所有驱动程序”);
fcm.订阅主题(“诱惑者”);
}
字符串getJobID(映射消息){
字符串jobID='';
if(Platform.isAndroid){
jobID=消息['data']['job_id'];
}
否则{
jobID=消息['job_id'];
打印('job_id:$jobID');
}
返回jobID;
}
void fetchJobInfo(字符串jobID,上下文){
//显示“请稍候”对话框
显示对话框(
禁止:错误,
上下文:上下文,
生成器:(BuildContext上下文)=>
ProgressDialog(状态:“正在获取详细信息…”,),
);
DatabaseReference jobRef=FirebaseDatabase.instance.reference().child(
“jobRequest/$jobID”);
jobRef.once().then((DataSnapshot快照){
Navigator.pop(上下文);
最终assetAudioPlayer=assetAudioPlayer();
如果(snapshot.value!=null){
打开(音频('sounds/sounds_alert.mp3');
assetAudioPlayer.play();
double destinationLat=double.parse(
snapshot.value['destination']['latitude'].toString();
double destination=double.parse(
snapshot.value['destination']['longitude'].toString());
字符串destinationAddress=snapshot.value['destination_address'];
字符串paymentMethod=snapshot.value['paymentMethod'];
JobDetails JobDetails=JobDetails();
jobDetails.jobID=jobID;
jobDetails.destinationAddress=destinationAddress;
jobDetails.destination=LatLng(destinationLat,destinationLat);
jobDetails.paymentMethod=paymentMethod;
//显示对话框(
//上下文:上下文,
//禁止:错误,
//生成器:(BuildContext上下文)=>NotificationDialog(jobDetails:jobDetails,),
// );
}
});
}
}

请参见下面最新的文档链接:-


它已经得到了回答,但有一张图片。您无法向iPhone模拟器获取通知

内部监督事务处;您必须有一个物理iOS设备才能接收消息。 Firebase云消息与Apple推送通知服务(APNs)集成,但APNs仅适用于真实设备


请查看最新的文档Hi Bholendra,谢谢您的回复。我已经试过了,但由于某种原因,还是不能让它工作。我上面的代码中是否有任何东西可能会导致您发现我做错了什么?