Flutter - фоновое уведомление с использованием FCM на IOS - PullRequest
1 голос
/ 14 октября 2019

Я пытаюсь получать тихие / фоновые push-уведомления на устройстве IOS с использованием Flutter. Мне удалось заставить это работать на Android, проблема в Just IOS.

Настройка - я использую плагин firebase_messaging 5.1.6 - я установил remote notifications и background fetch в XCode, а такжевключены Push-уведомления в Capabilities - Push-уведомления с данными, кажется, работают нормально

Моя полезная нагрузка (я пробовал с данными и без данных)

{"registration_ids":["<IOS DEVICE IDS>"],"priority":"high","content_available":true,"mutable_content":true,"data":{"title":"Title.","body":"Message."}}

Моя конфигурация Firebase ниже:

Причина, по которой onBackgroundMessage установлено в ноль, заключается в том, что я получаю ошибку ниже:

Unhandled Exception: MissingPluginException(No implementation found for method FcmDartService#start on channel plugins.flutter.io/firebase_messaging)
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
  // test code
  NetworkService networkService = NetworkService();
  networkService.getData("test"); // hit a test endpoint to make sure the code excuted

  print("myBackgroundMessageHandler: $message");
}

_firebaseMessaging.configure(
    onMessage: (Map<String, dynamic> message) async {
      print("onMessage: $message");
      NetworkService networkService = NetworkService();
      networkService.getData("test");
    },
    onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
    onLaunch: (Map<String, dynamic> message) async {
      print("onLaunch: $message");
    },
    onResume: (Map<String, dynamic> message) async {
      print("onResume: $message");
    },
  );

Полная ошибка

2019-10-15 08:44:52.766262+0100 Runner[16132:1794539]  - <AppMeasurement>[I-ACS036001] Analytics screen reporting is disabled. UIViewController transitions will not be logged.
2019-10-15 08:44:52.909787+0100 Runner[16132:1794333] Metal API Validation Enabled
2019-10-15 08:44:53.173885+0100 Runner[16132:1794552] flutter: Observatory listening on http://127.0.0.1:58105/hC1vIwLgB_o=/
2019-10-15 08:44:53.294824+0100 Runner[16132:1794539] 6.9.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60102000 started
2019-10-15 08:44:53.295297+0100 Runner[16132:1794539] 6.9.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
2019-10-15 08:44:53.940639+0100 Runner[16132:1794545] flutter: 1 /var/mobile/Containers/Data/Application/E0ADA03B-747D-4A66-9A96-97160F70D80A/Documents/db
2019-10-15 08:44:54.030056+0100 Runner[16132:1794545] [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method FcmDartService#start on channel plugins.flutter.io/firebase_messaging)
#0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
<asynchronous suspension>
#1      FirebaseMessaging.configure (package:firebase_messaging/firebase_messaging.dart:118:16)
#2      configureFirebaseMessaging (package:gard/utilities/service_locator.dart:53:22)
#3      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6)
#4      configureFirebaseMessaging (package:gard/utilities/service_locator.dart:47:40)
#5      main (package:gard/main.dart:31:9)
#6      _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#7      _rootRunUnary (dart:async/zone.dart:1132:38)
#8      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#9      _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#11     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#12     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#13     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#14     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#15     setupDatabase (package:gard/utilities/service_locator.dart)
#16     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#17     _rootRunUnary (dart:async/zone.dart:1132:38)
#18     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#19     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#20     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#21     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#22     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#23     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#24     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#25     DatabaseCreator.initDatabase (package:gard/database/database_creator.dart)
#26     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#27     _rootRunUnary (dart:async/zone.dart:1132:38)
#28     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#29     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#30     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#31     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#32     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#33     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#34     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#35     BasicLock.synchronized (package:synchronized/src/basic_lock.dart)
#36     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#37     _rootRunUnary (dart:async/zone.dart:1132:38)
#38     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#39     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#40     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#41     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#42     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#43     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#44     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#45     ReentrantLock.synchronized.<anonymous closure> (package:synchronized/src/reentrant_lock.dart)
#46     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#47     _rootRunUnary (dart:async/zone.dart:1132:38)
#48     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#49     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#50     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#51     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#52     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#53     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#54     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#55     SqfliteDatabaseFactoryMixin.openDatabase.<anonymous closure> (package:sqflite/src/factory_mixin.dart)
#56     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#57     _rootRunUnary (dart:async/zone.dart:1132:38)
#58     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#59     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#60     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#61     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#62     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#63     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#64     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#65     SqfliteDatabaseOpenHelper.openDatabase (package:sqflite/src/database.dart)
#66     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#67     _rootRunUnary (dart:async/zone.dart:1132:38)
#68     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#69     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#70     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#71     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#72     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#73     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#74     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#75     SqfliteDatabaseMixin.doOpen (package:sqflite/src/database_mixin.dart)
#76     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#77     _rootRunUnary (dart:async/zone.dart:1132:38)
#78     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#79     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#80     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#81     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#82     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#83     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#84     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#85     SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart)
#86     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#87     _rootRunUnary (dart:async/zone.dart:1132:38)
#88     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#89     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#90     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#91     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#92     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#93     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#94     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#95     SqfliteDatabaseMixin._runTransaction (package:sqflite/src/database_mixin.dart)
#96     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#97     _rootRunUnary (dart:async/zone.dart:1132:38)
#98     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#99     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#100    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#101    Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#102    Future._completeWithValue (dart:async/future_impl.dart:522:5)
#103    _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#104    _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#105    SqfliteDatabaseMixin.endTransaction (package:sqflite/src/database_mixin.dart)
#106    _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#107    _rootRunUnary (dart:async/zone.dart:1132:38)
#108    _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#109    _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#110    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#111    Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#112    Future._completeWithValue (dart:async/future_impl.dart:522:5)
#113    _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#114    _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#115    SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart)
#116    _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#117    _rootRunUnary (dart:async/zone.dart:1132:38)
#118    _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#119    _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#120    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#121    Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#122    Future._completeWithValue (dart:async/future_impl.dart:522:5)
#123    _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#124    _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#125    wrapDatabaseException (package:sqflite/src/exception_impl.dart)
#126    _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#127    _rootRunUnary (dart:async/zone.dart:1132:38)
#128    _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#129    _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#130    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#131    Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#132    Future._completeWithValue (dart:async/future_impl.dart:522:5)
#133    _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#134    _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#135    MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart)
#136    _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#137    _rootRunUnary (dart:async/zone.dart:1132:38)
#138    _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#139    _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#140    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#141    Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#142    Future._completeWithValue (dart:async/future_impl.dart:522:5)
#143    Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
#144    _rootRun (dart:async/zone.dart:1124:13)
#145    _CustomZone.run (dart:async/zone.dart:1021:19)
#146    _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#147    _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#148    _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#149    _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
2019-10-15 08:44:54.520569+0100 Runner[16132:1794333] [TSBackgroundFetch configure]: {
    enableHeadless = 1;
    minimumFetchInterval = 15;
    stopOnTerminate = 0;
}
2019-10-15 08:44:54.525630+0100 Runner[16132:1794333] [TSBackgroundFetch addListener]: com.transistorsoft/flutter_background_fetch
2019-10-15 08:44:54.525691+0100 Runner[16132:1794333] [TSBackgroundFetch start]
2019-10-15 08:44:54.761953+0100 Runner[16132:1794545] flutter: ---- BackgroundFetch configure success: 2
2019-10-15 08:44:56.139196+0100 Runner[16132:1794545] flutter: -----setNotificationToken-----
2019-10-15 08:44:56.139413+0100 Runner[16132:1794545] flutter: fSpD_VrnO2k:APA91bEwfT083oNVxPDy-kiF9mTPZiyoQbS2owQTK18erSARU8akzANG6H1zWr5bgMpAePkx3jc3F3spSAOSsf4Wr_zj3bDEi1yw1E5UeHSJCsMh3flDxNxq2mE__FwhiP2M35szQi0l
...