Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] flutter: scheduleTask ERROR: PlatformException #107

Closed
kleber-rr opened this issue Mar 26, 2020 · 33 comments
Closed

[BUG] flutter: scheduleTask ERROR: PlatformException #107

kleber-rr opened this issue Mar 26, 2020 · 33 comments

Comments

@kleber-rr
Copy link

kleber-rr commented Mar 26, 2020

Your Environment

  • Plugin version: 0.5.5
  • Platform: iOS
  • OS version: 13.4 (tested also on 13.3)
  • Device manufacturer / model: iPhone 7
  • Flutter info (flutter info, flutter doctor):
    Flutter 1.15.21-pre.22 • channel master • https://github.com/flutter/flutter.git
    Framework • revision 37a93a7ad9 (2 weeks ago) • 2020-03-12 17:06:02 -0400
    Engine • revision 1aaf169882
    Tools • Dart 2.8.0 (build 2.8.0-dev.13.0 17eec5bcde)`
  • Plugin config

To Reproduce
Steps to reproduce the behavior:

  1. Config as guide in xCode.
  2. Write my code:
@override
  void initState() {
    super.initState();
    configBackgroundTask();
  }

void _onBackgroundFetch(String taskId) async {
    debugPrint('>>[_onBackgroundFetch] configBackgroundTask taskId: $taskId');
    DateTime timestamp = new DateTime.now();
    print("###[_onBackgroundFetch] Event received: $taskId on ${timestamp.toString()}" );
    switch (taskId) {
      case 'com.transistorsoft.customtask': print ('Minha tarefa personalizada acionada'); 
        break; 
      default: print('Evento de busca em segundo plano acionado');
    } 
    listaFavoritos = await FuncoesExtras.getAllFavoritosSF();
    
    onSendMessageInBackGround();
    
    _events.insert(0, "$taskId@${timestamp.toString()}");
    
    FuncoesExtras.saveEvents(jsonEncode(_events));

    if (taskId == "flutter_background_fetch") {
       BackgroundFetch.scheduleTask(
         TaskConfig(
          taskId: "com.transistorsoft.customtask",
          delay: TIME_SCHEDULE_MIN,
          periodic: false,
          forceAlarmManager: true,
          stopOnTerminate: false,
          enableHeadless: true)).then((value) => print("BackgroundFetch.scheduleTask.SCHEDULE.RESULT: " + value.toString()));
    }
    BackgroundFetch.finish(taskId);
  }

Debug logs
None

  • ios XCode logs,
2020-03-26 16:43:47.048256-0400 Runner[1100:525502] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      BackgroundFetch.scheduleTask (package:background_fetch/background_fetch.dart:475:33)
#4      _MyAppState._onBackgroundFetch (package:economizarr/main.dart:266:24)
#5      _rootRunUnary (dart:async/zone.dart:1134:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#9      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#10     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#11     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:34:15)
#12     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:293:13)
#13     FuncoesExtras.getAllFavoritosSF (package:economizarr/utils/funcoes_extras.dart)
#14     _rootRunUnary (dart:async/zone.dart:1134:38)
#15     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#16     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#17     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#18     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#19     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#20     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#21     _rootRun (dart:async/zone.dart:1126:13)
#22     _CustomZone.run (dart:async/zone.dart:1023:19)
#23     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#24     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#25     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#26     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
2020-03-26 16:47:29.821288-0400 Runner[1100:525286] dnssd_clientstub read_all(17) DEFUNCT
2020-03-26 16:47:29.821553-0400 Runner[1100:525286] [VERBOSE-2:FlutterObservatoryPublisher.mm(131)] Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
  • Android: $ adb logcat

Additional context

import UIKit
import Flutter
import UserNotifications
import CoreML

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        GeneratedPluginRegistrant.register(with: self)
        UNUserNotificationCenter.current().delegate = self
        application.registerForRemoteNotifications()
        
        if(!UserDefaults.standard.bool(forKey: "Notification")) {
            let center = UNUserNotificationCenter.current()
            center.removeAllDeliveredNotifications() // To remove all delivered notifications
            center.removeAllPendingNotificationRequests()
            UserDefaults.standard.set(true, forKey: "Notification")
        }
        
        if #available(iOS 13.0, *) {
            NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIScene.willDeactivateNotification, object: nil)
        } else {
            NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIApplication.willResignActiveNotification, object: nil)
        }
        print("#SWIFT - didFinishLaunchingWithOptions - desativando o uso da CPU em background")
        let options = MLPredictionOptions()
        options.usesCPUOnly = true // Can't use GPU in the background
//
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

Add any other context about the problem here.

I have this problem only on IOS. Whenever I activate "Start due to a background search event" in xcode and run the application, it reports this error at startup.
I also read and implemented the recommendations in "See the iOS setup guide"
Sometimes, this error does not appear (rarely), but notifications are not displayed and there are no errors. Even when I start the app normally, it doesn't display any errors.
Any idea what it might be?

@christocracy
Copy link
Member

Please review iOS Setup

@kleber-rr
Copy link
Author

Please review iOS Setup

thanks for answering. I have already reviewed this setup several times. This is my complete Info.plist:

`

BGTaskSchedulerPermittedIdentifiers com.transistorsoft.customtask com.transistorsoft.fetch CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier ${PRODUCT_BUNDLE_IDENTIFIER} CFBundleInfoDictionaryVersion 6.0 CFBundleName EconomizaRR CFBundlePackageType APPL CFBundleShortVersionString $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion $(CURRENT_PROJECT_VERSION) LSApplicationQueriesSchemes googlechromes comgooglemaps waze LSRequiresIPhoneOS NSCameraUsageDescription Para escanear o código de barras NSLocationAlwaysUsageDescription Para consultar o estabelecimento mais próximo de você NSLocationWhenInUseUsageDescription Para consultar o estabelecimento mais próximo de você UIBackgroundModes fetch processing remote-notification UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance `

@christocracy
Copy link
Member

Here's my XCode log after Launch from Background Fetch:

2020-03-27 10:42:57.475821-0400 Runner[63030:26077232] [TSBackgroundFetch load]: (
    "<TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>"
)
2020-03-27 10:42:57.475883-0400 Runner[63030:26077232] [TSBGAppRefreshSubscriber load]: {
    "flutter_background_fetch" = "<TSBGAppRefreshSubscriber identifier=flutter_background_fetch, executed=0, enabled=1>";
}
2020-03-27 10:42:57.635349-0400 Runner[63030:26077232] Metal API Validation Enabled
2020-03-27 10:42:57.816047-0400 Runner[63030:26077296] flutter: Observatory listening on http://127.0.0.1:63472/S99yi6TBidc=/
2020-03-27 10:42:57.839015-0400 Runner[63030:26077232] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.customtask
2020-03-27 10:42:57.846031-0400 Runner[63030:26077232] BackgroundFetch AppDelegate received fetch event
2020-03-27 10:42:57.846054-0400 Runner[63030:26077232] [TSBackgroundFetch performFetchWithCompletionHandler]
2020-03-27 10:42:57.846059-0400 Runner[63030:26077232] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-03-27 10:42:58.428435-0400 Runner[63030:26077232] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>
2020-03-27 10:42:58.430392-0400 Runner[63030:26077278] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-03-27 10:42:58.434879-0400 Runner[63030:26077278] flutter: [BackgroundFetch] configure success: 2
2020-03-27 10:42:58.439202-0400 Runner[63030:26077232] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>
2020-03-27 10:42:58.443205-0400 Runner[63030:26077232] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)
2020-03-27 10:53:35.190297-0400 Runner[63030:26077232] dnssd_clientstub read_all(17) DEFUNCT
2020-03-27 10:53:35.190406-0400 Runner[63030:26077232] [VERBOSE-2:FlutterObservatoryPublisher.mm(131)] Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
2020-03-27 10:53:35.293652-0400 Runner[63030:26077270] [TSBackgroundFetch handleBGAppRefreshTask]
2020-03-27 10:53:35.293736-0400 Runner[63030:26077270] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-03-27 10:53:35.300479-0400 Runner[63030:26077278] flutter: [BackgroundFetch] Event received: com.transistorsoft.customtask
2020-03-27 10:53:35.308751-0400 Runner[63030:26077278] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-03-27 10:53:35.317897-0400 Runner[63030:26077232] [TSBGTask destroy] com.transistorsoft.customtask
2020-03-27 10:53:35.319341-0400 Runner[63030:26077232] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=0>
2020-03-27 10:53:35.323294-0400 Runner[63030:26077232] [TSBGTask save]: <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>
2020-03-27 10:53:35.323787-0400 Runner[63030:26077232] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)

@christocracy
Copy link
Member

You're not doing this on a simulator, are you? The simulator doesn't work well with new fetch API. Best to test on a real device.

@kleber-rr
Copy link
Author

do not. iPhone 7 real

@RYANCOAL9999
Copy link

RYANCOAL9999 commented Apr 14, 2020

Here is the new problem. It is using the example build iPhone 8 plus with iOS 13.4.

2020-04-14 14:02:15.657191+0800 Runner[2994:811445] [TSBackgroundFetch load]: ()
2020-04-14 14:02:15.657626+0800 Runner[2994:811445] [TSBGAppRefreshSubscriber load]: {}
2020-04-14 14:02:16.110376+0800 Runner[2994:811445] Metal API Validation Enabled
2020-04-14 14:02:16.423020+0800 Runner[2994:811445] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.customtask
2020-04-14 14:02:16.732969+0800 Runner[2994:811445] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=0>
2020-04-14 14:02:16.734637+0800 Runner[2994:811445] [TSBackgroundFetch scheduleTask] ERROR:  Failed to submit task request: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)"
2020-04-14 14:02:16.736679+0800 Runner[2994:811672] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321)
<asynchronous suspension>
#2      BackgroundFetch.scheduleTask (package:background_fetch/background_fetch.dart:475)
#3      _MyAppState.initPlatformState (package:background_fetch_example/main.dart:109)
#4      _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73)
#5      _rootRunUnary (dart:async/zone.dart:1134)
#6      _CustomZone.runUnary (dart:async/zone.dart:1031)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:139)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680)
#9      Future._propagateToListeners (dart:async/future_impl.dart:709)
#10     Future._completeWithValue (dart:async/future_impl.dart:524)
#11     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554)
#12     _rootRun (dart:async/zone.dart:1126)
#13     _CustomZone.run (dart:async/zone.dart:1023)
#14     _CustomZone.runGuarded (dart:async/zone.dart:925)
#15     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965)
#16     _microtaskLoop (dart:async/schedule_microtask.dart:43)
#17     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52)
2020-04-14 14:02:16.736846+0800 Runner[2994:811445] - flutter_background_fetch failed to start, status: 1
2020-04-14 14:02:16.737418+0800 Runner[2994:811672] flutter: [BackgroundFetch] configure ERROR: 1
2020-04-14 14:02:44.540094+0800 Runner[2994:811672] flutter: [BackgroundFetch] status: 1
2020-04-14 14:02:44.761629+0800 Runner[2994:811672] flutter: [BackgroundFetch] status: 1
2020-04-14 14:02:56.062761+0800 Runner[2994:811445] BackgroundFetch AppDelegate received fetch event
2020-04-14 14:02:56.062894+0800 Runner[2994:811445] [TSBackgroundFetch performFetchWithCompletionHandler]
2020-04-14 14:02:56.062962+0800 Runner[2994:811445] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-04-14 14:02:56.065206+0800 Runner[2994:811672] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-04-14 14:02:56.066370+0800 Runner[2994:811445] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=0>
2020-04-14 14:02:56.067368+0800 Runner[2994:811445] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)
2020-04-14 14:02:56.067897+0800 Runner[2994:811672] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321)

@christocracy
Copy link
Member

@RYANCOAL9999 are you executing this in the iOS simulator?

@RYANCOAL9999
Copy link

No, I am using the real iPhone 8 plus.

@christocracy
Copy link
Member

@RYANCOAL9999 Did you Configure Info.plist and add com.transistorsoft.customtask to Permitted background task schedule identifiers?

@RYANCOAL9999
Copy link

yes, it is added. I am using your project's example.

@christocracy
Copy link
Member

christocracy commented Apr 15, 2020

@RYANCOAL9999 I just cloned this repo and launched the /example app in this repo and everything works as normal.

@kleber-rr
Copy link
Author

I did that too: I cloned the repo and lanched the /example, but it didn't work in the real iphone 7 device.

@christocracy
Copy link
Member

BGTaskSchedulerErrorDomain Code=1 = unavailable

@christocracy
Copy link
Member

I have no issues on iPhone 6s @ 13.4.1.

@kleber-rr
Copy link
Author

what is your sdk flutter configuration and other plugins?

@christocracy
Copy link
Member

Flutter sdk cannot affect this. Only iOS version / device settings. This error comes directly from iOS:

Failed to submit task request: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)"
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale en-CA)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.41.1)
[✓] Connected device (3 available)

@RYANCOAL9999
Copy link

RYANCOAL9999 commented Apr 16, 2020

yes, The flutter sdk can not effect this. I just cloned this repo and launched the /example app in this repo. But, my testing error is not Failed to submit task request: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)". My testing error is [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null). May be the this example is miss some steps ?

@christocracy
Copy link
Member

You must have disabled Background Refresh in your device settings.

3BDA5D15-A2D5-41B3-B163-4B7C58F630A8

@christocracy
Copy link
Member

And the big Flutter exception is thrown on purpose by the plugin because iOS said BGTaskSchedulerErrorDomain Code=1

@kleber-rr
Copy link
Author

kleber-rr commented Apr 16, 2020

I tried the whole process of installing the example:
1 - after downloading and opening in vscode, I executed the "flutter pub get";
2 - edited the Podfile, removing the # from line 2;
3 - cd ios, pod install;
4 - flutter run

in the foreground, in the xcode console, the log I have is this:

    "<TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>"
)
2020-04-16 08:35:47.019979-0400 Runner[3156:2112792] [TSBGAppRefreshSubscriber load]: {
    "flutter_background_fetch" = "<TSBGAppRefreshSubscriber identifier=flutter_background_fetch, executed=0, enabled=1>";
}
2020-04-16 08:35:47.384358-0400 Runner[3156:2112792] Metal API Validation Enabled
2020-04-16 08:35:47.489194-0400 Runner[3156:2112792] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.customtask
2020-04-16 08:35:47.540604-0400 Runner[3156:2112988] flutter: Observatory listening on http://127.0.0.1:51144/QIzDvCBNmX0=/
2020-04-16 08:35:48.361235-0400 Runner[3156:2112792] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-04-16 08:35:48.369525-0400 Runner[3156:2112792] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>
2020-04-16 08:35:48.373745-0400 Runner[3156:2112980] flutter: [BackgroundFetch] configure success: 2

no exceptions are thrown (I left 20 minutes with the app running on xcode like this)

now when i edit the xcode schema and set it to launch due to background fetch event, it displays the following console when booting from xcode:

2020-04-16 09:02:06.676807-0400 Runner[3168:2119207] [TSBackgroundFetch load]: (
    "<TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>"
)
2020-04-16 09:02:06.677187-0400 Runner[3168:2119207] [TSBGAppRefreshSubscriber load]: {
    "flutter_background_fetch" = "<TSBGAppRefreshSubscriber identifier=flutter_background_fetch, executed=0, enabled=1>";
}
2020-04-16 09:02:07.088911-0400 Runner[3168:2119207] Metal API Validation Enabled
2020-04-16 09:02:07.210894-0400 Runner[3168:2119207] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.customtask
2020-04-16 09:02:07.225504-0400 Runner[3168:2119207] BackgroundFetch AppDelegate received fetch event
2020-04-16 09:02:07.225583-0400 Runner[3168:2119207] [TSBackgroundFetch performFetchWithCompletionHandler]
2020-04-16 09:02:07.225615-0400 Runner[3168:2119207] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-04-16 09:02:07.272274-0400 Runner[3168:2119391] flutter: Observatory listening on http://127.0.0.1:52649/8NE1K_7zqPg=/
2020-04-16 09:02:07.993112-0400 Runner[3168:2119207] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-04-16 09:02:07.994220-0400 Runner[3168:2119207] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>
2020-04-16 09:02:08.002700-0400 Runner[3168:2119384] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-04-16 09:02:08.006819-0400 Runner[3168:2119384] flutter: [BackgroundFetch] configure success: 2
2020-04-16 09:02:08.006892-0400 Runner[3168:2119207] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>
2020-04-16 09:02:08.008594-0400 Runner[3168:2119207] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)
2020-04-16 09:02:08.011682-0400 Runner[3168:2119384] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      BackgroundFetch.scheduleTask (package:background_fetch/background_fetch.dart:475:33)
#4      _MyAppState.initPlatformState (package:background_fetch_example/main.dart:109:21)
#5      _rootRunUnary (dart:async/zone.dart:1192:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#9      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#10     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#11     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#12     _rootRun (dart:async/zone.dart:1184:13)
#13     _CustomZone.run (dart:async/zone.dart:1077:19)
#14     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#15     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#16     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#17     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
2020-04-16 09:02:08.014876-0400 Runner[3168:2119384] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      BackgroundFetch.scheduleTask (package:background_fetch/background_fetch.dart:475:33)
#4      _MyAppState._onBackgroundFetch (package:background_fetch_example/main.dart:143:23)
#5      _rootRunUnary (dart:async/zone.dart:1192:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#9      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#10     Future._addListener.<anonymous closure> (dart:async/future_impl.dart:391:9)
#11     _rootRun (dart:async/zone.dart:1184:13)
#12     _CustomZone.run (dart:async/zone.dart:1077:19)
#13     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#14     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#15     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#16     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)

i'm using ios 13.4, running on real iphone 7, and background updates permissions are enabled.
really, i can't find my mistake.
IMG_0439
sometimes (rare) the app displays a notification. i know that apple handles tasks in a very peculiar way, but i am not getting ahead here.

@christocracy
Copy link
Member

edited the Podfile, removing the # from line 2;

Why??

@kleber-rr
Copy link
Author

because he indicated this warning when updating the pod (pod install):

!] Automatically assigning platform iOS with version 8.0 on target Runner because no platform was specified. Please specify a platform for this target in your Podfile. See https: // guides.cocoapods.org / syntax / podfile.html # platform.

@christocracy
Copy link
Member

christocracy commented Apr 16, 2020

That Podfile is the auto-generated default by Flutter itself. Don't touch it.
/example (booted in XCode with [x] Launch due to background fetch event)

@kleber-rr
Copy link
Author

kleber-rr commented Apr 17, 2020

same problem.

    "<TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>"
)
2020-04-17 08:06:10.085089-0400 Runner[3978:2830744] [TSBGAppRefreshSubscriber load]: {
    "flutter_background_fetch" = "<TSBGAppRefreshSubscriber identifier=flutter_background_fetch, executed=0, enabled=1>";
}
2020-04-17 08:06:13.067982-0400 Runner[3978:2830744] Metal API Validation Enabled
2020-04-17 08:06:13.308075-0400 Runner[3978:2830744] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.customtask
2020-04-17 08:06:13.325401-0400 Runner[3978:2830744] BackgroundFetch AppDelegate received fetch event
2020-04-17 08:06:13.325494-0400 Runner[3978:2830744] [TSBackgroundFetch performFetchWithCompletionHandler]
2020-04-17 08:06:13.325532-0400 Runner[3978:2830744] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-04-17 08:06:13.363123-0400 Runner[3978:2830991] flutter: Observatory listening on http://127.0.0.1:54862/h_tZ034JgVI=/
2020-04-17 08:06:14.348798-0400 Runner[3978:2830744] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-04-17 08:06:14.350458-0400 Runner[3978:2830744] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>
2020-04-17 08:06:14.495445-0400 Runner[3978:2830982] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-04-17 08:06:14.499257-0400 Runner[3978:2830982] flutter: [BackgroundFetch] configure success: 2
2020-04-17 08:06:14.499382-0400 Runner[3978:2830744] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>
2020-04-17 08:06:14.500701-0400 Runner[3978:2830744] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)
2020-04-17 08:06:14.503821-0400 Runner[3978:2830982] [VERBOSE-2:ui_dart_state.cc(157)] **Unhandled Exception: PlatformException(1, null, null)**
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      BackgroundFetch.scheduleTask (package:background_fetch/background_fetch.dart:475:33)
#4      _MyAppState.initPlatformState (package:background_fetch_example/main.dart:109:21)
#5      _rootRunUnary (dart:async/zone.dart:1192:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#9      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#10     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#11     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#12     _rootRun (dart:async/zone.dart:1184:13)
#13     _CustomZone.run (dart:async/zone.dart:1077:19)
#14     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#15     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#16     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#17     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
2020-04-17 08:06:14.505886-0400 Runner[3978:2830982] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(1, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      BackgroundFetch.scheduleTask (package:background_fetch/background_fetch.dart:475:33)
#4      _MyAppState._onBackgroundFetch (package:background_fetch_example/main.dart:143:23)
#5      _rootRunUnary (dart:async/zone.dart:1192:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#9      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#10     Future._addListener.<anonymous closure> (dart:async/future_impl.dart:391:9)
#11     _rootRun (dart:async/zone.dart:1184:13)
#12     _CustomZone.run (dart:async/zone.dart:1077:19)
#13     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#14     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#15     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#16     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)

@christocracy
Copy link
Member

I have no idea. iOS says this.

You can catch this error in your dart code instead of leaving it uncaught.

@kleber-rr
Copy link
Author

Guys, I found one thing: the project initially comes standard with iOS version 8.0. When I run the app in Xcode, with this version, it does not report any errors (although it does not run the service in the background at any time of the day).

However, when I change the version to 13.4, the referred error of this topic appears.

I know that it was informed that background-fetch is obsolete, but has not yet been discontinued in iOS 13, but there must be a problem, as it only presents this exception when moving to the most current version.

@christocracy
Copy link
Member

@kleber-rr flutter doctor

@kleber-rr
Copy link
Author

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale pt-BR)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.44.2)
[✓] Connected device (1 available)

• No issues found!

@christocracy
Copy link
Member

Have you tried the /example app in this repo?

@kleber-rr
Copy link
Author

yes.

@christocracy
Copy link
Member

Are you running the /example app without touching anything? It works me right out of the box.

However, when I change the version to 13.4, the referred error of this topic appears.

If you're talking about this, that's merely the minimum iOS version your app targets.

I suggest you completely terminate XCode and restart your machine.

@kleber-rr
Copy link
Author

kleber-rr commented May 4, 2020

yes to all your questions. I have restarted the mac several times.

however today, I once again, running the code through xCode, got the following result:

2020-05-04 07:55:37.419504-0400 Runner[575:314413] [TSBackgroundFetch load]: (
    "<TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>"
)
2020-05-04 07:55:37.419915-0400 Runner[575:314413] [TSBGAppRefreshSubscriber load]: {
    "flutter_background_fetch" = "<TSBGAppRefreshSubscriber identifier=flutter_background_fetch, executed=0, enabled=1>";
}
2020-05-04 07:55:41.372174-0400 Runner[575:314413] Metal API Validation Enabled
2020-05-04 07:55:41.610848-0400 Runner[575:314664] flutter: Observatory listening on http://127.0.0.1:49898/87L2i6NCh-s=/
2020-05-04 07:55:41.611375-0400 Runner[575:314413] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.customtask
2020-05-04 07:55:41.627876-0400 Runner[575:314413] BackgroundFetch AppDelegate received fetch event
2020-05-04 07:55:41.627977-0400 Runner[575:314413] [TSBackgroundFetch performFetchWithCompletionHandler]
2020-05-04 07:55:41.628018-0400 Runner[575:314413] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-05-04 07:55:42.579521-0400 Runner[575:314413] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=10, periodic=0 enabled=1>
2020-05-04 07:55:42.599936-0400 Runner[575:314656] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-05-04 07:55:42.607427-0400 Runner[575:314413] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>
2020-05-04 07:55:42.613002-0400 Runner[575:314413] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)
2020-05-04 07:55:42.615033-0400 Runner[575:314656] flutter: [BackgroundFetch] configure success: 2
2020-05-04 08:03:24.570974-0400 Runner[575:314413] dnssd_clientstub read_all(9) DEFUNCT
2020-05-04 08:03:24.571666-0400 Runner[575:314413] [VERBOSE-2:FlutterObservatoryPublisher.mm(131)] Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
2020-05-04 08:03:24.600809-0400 Runner[575:314645] [TSBackgroundFetch handleBGAppRefreshTask]
2020-05-04 08:03:24.601072-0400 Runner[575:314645] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch
2020-05-04 08:03:24.981970-0400 Runner[575:314640] Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)
2020-05-04 08:03:24.982429-0400 Runner[575:314640] Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)
2020-05-04 08:03:24.982765-0400 Runner[575:314640] Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)
2020-05-04 08:03:24.983048-0400 Runner[575:314640] Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)
2020-05-04 08:03:24.983730-0400 Runner[575:314640] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=7 "Insufficient Permission (to submit GPU work from background) (IOAF code 6)" UserInfo={NSLocalizedDescription=Insufficient Permission (to submit GPU work from background) (IOAF code 6)}
2020-05-04 08:03:24.984361-0400 Runner[575:314656] flutter: [BackgroundFetch] Event received: com.transistorsoft.customtask
2020-05-04 08:03:24.985734-0400 Runner[575:314656] flutter: [BackgroundFetch] Event received: flutter_background_fetch
2020-05-04 08:03:24.991433-0400 Runner[575:314413] [TSBGTask destroy] com.transistorsoft.customtask
2020-05-04 08:03:24.992564-0400 Runner[575:314413] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=0>
2020-05-04 08:03:25.000349-0400 Runner[575:314413] [TSBGTask save]: <TSBGTask identifier=com.transistorsoft.customtask, delay=5, periodic=0 enabled=1>
2020-05-04 08:03:25.001286-0400 Runner[575:314413] [TSBackgroundFetch finish] flutter_background_fetch (1 of 1)

@christocracy
Copy link
Member

I've never heard of this. I don't thing this is directly related to the plugin.

2020-05-04 08:03:24.983048-0400 Runner[575:314640] Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)
2020-05-04 08:03:24.983730-0400 Runner[575:314640] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=7 "Insufficient Permission (to submit GPU work from background) (IOAF code 6)" UserInfo={NSLocalizedDescription=Insufficient Permission (to submit GPU work from background) (IOAF code 6)}
.
.
.
2020-05-04 08:03:24.984361-0400 Runner[575:314656] flutter: [BackgroundFetch] Event received: com.transistorsoft.customtask
2020-05-04 08:03:24.985734-0400 Runner[575:314656] flutter: [BackgroundFetch] Event received: flutter_background_fetch

Both the fetch task flutter_background_fetch and custom-task com.transistorsoft.customtask were successfully received by your Javascript callback. I suggest you google the error "Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)"

It seems your original issue is solved.

flutter: scheduleTask ERROR: PlatformException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants