Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Flutter 如何使ios上的Workmanager颤振_Flutter - Fatal编程技术网

Flutter 如何使ios上的Workmanager颤振

Flutter 如何使ios上的Workmanager颤振,flutter,Flutter,我在一个项目中运行workmanager,使应用程序在后台运行,而用户不在应用程序中。现在的问题是Android上的应用程序正在运行,但当它在iOS和Mac上的模拟器上运行时,出现了以下问题: [VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel be.tramckrijte.wor

我在一个项目中运行workmanager,使应用程序在后台运行,而用户不在应用程序中。现在的问题是Android上的应用程序正在运行,但当它在iOS和Mac上的模拟器上运行时,出现了以下问题:

[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel be.tramckrijte.workmanager/foreground_channel_work_manager)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:7)
<asynchronous suspension>
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
#2      Workmanager.initialize (package:workmanager/src/workmanager.dart:100:30)
#3      _MyHomePageState.initState (package:toios/main.dart:58:17)
#4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
#5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#7      Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#8      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
#9      Element.inflat<…>
[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method registerPeriodicTask on channel be.tramckrijte.workmanager/foreground_channel_work_manager)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:7)
<asynchronous suspension>
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
#2      Workmanager.registerPeriodicTask (package:workmanager/src/workmanager.dart:158:32)
#3      _MyHomePageState.initState (package:toios/main.dart:63:17)
#4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
#5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#7      Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#8      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
#9<…>

有人知道如何解决在iOS上运行的问题吗

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:workmanager/workmanager.dart';
import 'package:toios/notification.dart' as notif;

const fetchBackground = "fetchBackground";

void callbackDispatcher() {
  Workmanager.executeTask((task, inputData) async {
    switch (task) {
      case fetchBackground:
        //Geolocator geoLocator = Geolocator()..forceAndroidLocationManager = true;
        Position userLocation = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
        notif.Notification notification = new notif.Notification();
        notification.showNotificationWithoutSound(userLocation);
        break;
    }
    return Future.value(true);
  });
}


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  void initState() {
    super.initState();

    // We don't need it anymore since it will be executed in background
    //this._getUserPosition();

    Workmanager.initialize(
      callbackDispatcher,
      isInDebugMode: true,
    );

    Workmanager.registerPeriodicTask(
        "1",
        fetchBackground,
        frequency: Duration(minutes: 30),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              "",
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
    );
  }
}


import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:geolocator/geolocator.dart';

class Notification {

  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

  Future showNotificationWithoutSound(Position position) async {
    print(position.toString());
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
        '1', 'location-bg', 'fetch location in background',
        playSound: false, importance: Importance.Max, priority: Priority.High);
    var iOSPlatformChannelSpecifics =
    new IOSNotificationDetails(presentSound: false);
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(
      0,
      'Location fetched',
      position.toString(),
      platformChannelSpecifics,
      payload: '',
    );
  }

  Notification() {
    var initializationSettingsAndroid = new AndroidInitializationSettings('@mipmap/ic_launcher');
    var initializationSettingsIOS = new IOSInitializationSettings();
    var initializationSettings = new InitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
    flutterLocalNotificationsPlugin.initialize(initializationSettings);
  }
}