Closed FlxGen closed 4 years ago
I've tried this on iOS 13.1.3 and iOS 13.2.2 and can't reproduce the crash.
I do get:
2019-11-15 15:01:31.611 BGCrash[325:7302] Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
2019-11-15 15:01:35.750 BGCrash[325:7302] Can't end BackgroundTask: no background task exists with identifier 4 (0x4), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
Can you please attach a project showing the problem.
I just saw this, let me try in Release and archived, but that shouldn't affect much...
***PLEASE NOTE: This crash only occurs AFTER submitting app to the App Store, it does not happen when running the app locally.
Still not seeing it - Can you please attach a project?
I'll make a stripped down version for you. I should also note it crashes in TestFlight. I'll try an ad-hoc install. Perhaps there is a TestFlight bug.
I've tried this on iOS 13.1.3 and iOS 13.2.2 and can't reproduce the crash.
I do get:
2019-11-15 15:01:31.611 BGCrash[325:7302] Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. 2019-11-15 15:01:35.750 BGCrash[325:7302] Can't end BackgroundTask: no background task exists with identifier 4 (0x4), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
Can you please attach a project showing the problem.
I get this too. I think it has something to do with the debugger because it doesn't happen if no debugger is attached.
I tried release mode on phone no debugger as well. Nothing yet.
App attached. I put it in to TestFlight and it has the same behavior.
For whatever reason the stack trace has more detail.
0 libsystem_kernel.dylib 0x00000001811a0efc __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001810c0d10 pthread_kill + 196 (pthread.c:1456)
2 libsystem_c.dylib 0x0000000181050af4 __abort + 116 (abort.c:147)
3 libsystem_c.dylib 0x0000000181050a80 abort + 116 (abort.c:118)
4 BackgroundCrash 0x00000001013a7dc4 xamarin_unhandled_exception_handler + 52 (runtime.m:1180)
5 BackgroundCrash 0x00000001012c8fc8 mono_invoke_unhandled_exception_hook + 132
6 BackgroundCrash 0x000000010126bf24 mono_handle_exception_internal + 5580
7 BackgroundCrash 0x000000010126a94c mono_handle_exception + 56
8 BackgroundCrash 0x0000000101261aa0 mono_arm_throw_exception + 376
9 BackgroundCrash 0x0000000101199ebc throw_exception + 172
10 BackgroundCrash 0x00000001013183bc mono_raise_exception + 64
11 BackgroundCrash 0x00000001013a7b30 xamarin_process_managed_exception + 376 (runtime.m:2441)
12 BackgroundCrash 0x00000001013a79ac xamarin_process_managed_exception_gchandle + 56 (runtime.m:1172)
13 BackgroundCrash 0x00000001013a7968 xamarin_ftnptr_exception_handler + 24 (runtime.m:1161)
14 BackgroundCrash 0x000000010126bc88 mono_handle_exception_internal + 4912
15 BackgroundCrash 0x000000010126a94c mono_handle_exception + 56
16 BackgroundCrash 0x0000000101261aa0 mono_arm_throw_exception + 376
17 BackgroundCrash 0x0000000101199ebc throw_exception + 172
18 BackgroundCrash 0x00000001010a67e4 System_Reflection_RuntimeConstructorInfo_DoInvoke_object_System_Reflection_BindingFlags_System_Re... + 452
19 BackgroundCrash 0x00000001010a68f8 System_Reflection_RuntimeConstructorInfo_Invoke_System_Reflection_BindingFlags_System_Reflection_... + 56
20 BackgroundCrash 0x000000010109af74 System_Reflection_ConstructorInfo_Invoke_object__ + 52
21 BackgroundCrash 0x00000001011d8fc8 ObjCRuntime_Runtime_ConstructNSObject_T_REF_intptr_System_Type_ObjCRuntime_Runtime_MissingCtorRes... + 216 (Runtime.cs:1133)
22 BackgroundCrash 0x00000001011d9be8 ObjCRuntime_Runtime_GetNSObject_T_REF_intptr + 376 (Runtime.cs:1274)
23 BackgroundCrash 0x00000001011df108 ObjCRuntime_Trampolines_SDActionArity1V16_Invoke_intptr_intptr + 88 (Trampolines.g.cs:15219)
24 BackgroundCrash 0x0000000101202408 wrapper_native_to_managed_ObjCRuntime_Trampolines_SDActionArity1V16_Invoke_intptr_intptr + 88
25 BackgroundTasks 0x00000001aa424ed0 __41-[BGTaskScheduler _runTask:registration:]_block_invoke.206 + 224 (BGTaskScheduler.m:446)
26 libdispatch.dylib 0x000000018105ab7c _dispatch_call_block_and_release + 32 (init.c:1408)
27 libdispatch.dylib 0x000000018105bfd8 _dispatch_client_callout + 20 (object.m:495)
28 libdispatch.dylib 0x0000000181062450 _dispatch_lane_serial_drain + 568 (inline_internal.h:2484)
29 libdispatch.dylib 0x0000000181062eb4 _dispatch_lane_invoke + 424 (inline_internal.h:1851)
30 libdispatch.dylib 0x000000018106bf20 _dispatch_workloop_worker_thread + 580 (queue.c:6445)
31 libsystem_pthread.dylib 0x00000001810c1a94 _pthread_wqthread + 280 (pthread.c:2323)
32 libsystem_pthread.dylib 0x00000001810c7c7c start_wqthread + 8
Xcode 11.3 beta (11C24b) corrects this issue so it must have been an iOS bug.
I spoke too soon.
I found an line on the console while the app quits. This has to be a Xamarin bug.
Unhandled Exception: System.MemberAccessException: Cannot create an instance of BackgroundTasks.BGTask because it is an abstract class
Interesting, we'll have to dig into this....
Would it be possible to bind this class as a work around or would I just get the same object?
This is a(nother) concrete example of why we need a fix for #4969.
- Is there a work around? (I'd really love to use this class)
Unfortunately I don't think there is a workaround, this is something we'll have to fix on our side.
- Why doesn't it happen with local installs?
Most likely AppStore installs hit another codepath inside iOS, where iOS uses a different subclass of BGTask (a private subclass) to do the work.
The issue is over a year old. Will this be fixed soon or should I use another method? BGTaskRequest is a great new feature and works MUCH (can't emphasize this enough via web browser) better than Background Fetch. That is to say, it would be very nice to have.
Please note, BGTaskRequest did initially work. It was broken during one of Apples many Xcode and iOS13 updates since 13 was released. Not sure which broke it.
Will this be fixed soon or should I use another method?
I would advice to use another method if you can, because even if we fixed the issue today, it would take months for it to reach a stable release.
@rolfbjarne @FlxGen @chamons Could you please have an update on this.A similar issue is here : https://github.com/xamarin/ios-samples/issues/392
"Refreshing and Maintaining Your App Using Background Tasks" this is not working.Apple's official swift version is working.Is there any solutions or workaround.People are eagerly waiting for this.
@donchakkappan Not sure if this is related. I get the callback, it just crashes when a BGTask is launched.
I agree with your assessment of the feature. The new background task scheduler is excellent compared to fetch. This should be escalated and fixed asap.
Most likely AppStore installs hit another codepath inside iOS, where iOS uses a different subclass of BGTask (a private subclass) to do the work.
Out of curiosity I tried an Ad-Hoc install with the same result. It must be the Mac host changing the codepath.
@FlxGen As the team continues investigating/fixing this bug, here's a workaround.
We can continue to use iOS 7-12's background fetch implementation: https://devblogs.microsoft.com/xamarin/add-background-data-refresh-to-ios-apps/
Apple marked it as deprecated, but it still works on iOS 13. Note that you'll have to remove BGTaskSchedulerPermittedIdentifiers
from Info.plist
.
Here's a sample demonstrating it on iOS 13: https://github.com/brminnick/BGBackgroundTaskWorkaround
public class AppDelegate : UIApplicationDelegate
{
public override UIWindow? Window { get; set; }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
return true;
}
public override async void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
var alertController = new UIAlertController
{
Title = "Background Fetch Triggered",
Message = "It's working!",
};
var currentViewController = Xamarin.Essentials.Platform.GetCurrentUIViewController();
await currentViewController.PresentViewControllerAsync(alertController, true);
completionHandler(UIBackgroundFetchResult.NoData);
}
}
API fixed, I'll test the application, if works as expected I'll backport the fix to d16-7 to be released in preview 2
@mandel-macaque Excellent, thanks!!!
@FlxGen can you please try the following pkg
If it fix your issue I'll merge https://github.com/xamarin/xamarin-macios/pull/8532
@mandel-macaque I will. I'll have an answer in a day or two.
@mandel-macaque I've never installed this before. Is there a doc with steps?
@FlxGen you just need to install it like a normal pkg and it will be used by default (you will need to re-start vsmac).
I do use the command line as follows, but you can simply double click:
sudo installer -pkg /path/to/the/downloaded.pkg -target /
@FlxGen any updates on this?
@mandel-macaque The issue appears to be resolved. Many thanks.
@FlxGen thanks for the confirmation, just backport it to d16-7. The fix will be in the next available preview.
FYI - this fix is now available in both the current Stable and Preview Channels, in Xamarin.iOS v13.18.2.1 & Xamarin.iOS v13.20.0.22
This issue is still reproducible with iOS 12 and below.
***PLEASE NOTE: This crash only occurs AFTER submitting app to the App Store, it does not happen when running the app locally. It may be an iOS bug but I'm opening it here because of the System.Reflection line in the stack trace. I'm not using any reflection in this part of my code (I've stripped out all my code in these blocks) so it's curious that after the background task is run that reflection is the next line. The iOS Build options are exactly the same between debug and release. Xcode version 11.2.1 (11B500).
Steps to Reproduce
BGTaskScheduler.Shared.Register("com.ios.dev.syncdata", null, task => { }
var appRefreshTaskRequest = new BGAppRefreshTaskRequest("com.ios.dev.syncdata") { EarliestBeginDate = null }; BGTaskScheduler.Shared.Submit(appRefreshTaskRequest, out NSError error);
Expected Behavior
Execute BGTask without crash.
Actual Behavior
Environment