Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

iOSで起動時にクラッシュすることがある不具合の対応 #1118

Merged
2 commits merged into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions Covid19Radar/Covid19Radar.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary launchOpt
// https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler/3180427-register
ScheduleBackgroundTasks();

try
{
LoggingPendingTaskRequests();
}
catch (Exception ex)
{
_loggerService.Value.Exception("Failure get pending task requests", ex);
}

return base.FinishedLaunching(app, launchOptions);
}

Expand Down Expand Up @@ -167,20 +158,6 @@ private void ScheduleBackgroundTasks()
_loggerService.Value.EndMethod();
}

private void LoggingPendingTaskRequests()
{
_loggerService.Value.Info($"Get pending task requests");
BGTaskScheduler.Shared.GetPending(pendingTaskRequests =>
{
_loggerService.Value.Info($"Pending task count: {pendingTaskRequests.Length}");
foreach (var pendingTaskRequest in pendingTaskRequests)
{
string identifier = pendingTaskRequest.Identifier.Split(".")?.Last();
_loggerService.Value.Info($"Identifier: {identifier}, EarliestBeginDate: {pendingTaskRequest.EarliestBeginDate}");
}
});
}

private bool IsUniversalLinks(NSDictionary launchOptions)
{
if (launchOptions == null)
Expand Down Expand Up @@ -293,15 +270,6 @@ public override void OnActivated(UIApplication uiApplication)
{
base.OnActivated(uiApplication);
MessagingCenter.Send((object)this, AppConstants.IosOnActivatedMessage);

try
{
LoggingPendingTaskRequests();
}
catch (Exception ex)
{
_loggerService.Value.Exception("Failure get pending task requests", ex);
}
}

private void RegisterPlatformTypes(IContainer container)
Expand Down
1 change: 1 addition & 0 deletions Covid19Radar/Covid19Radar.iOS/Covid19Radar.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
<Compile Include="Services\LocalPathService.cs" />
<Compile Include="Services\EventLogSubmissionBackgroundService.cs" />
<Compile Include="Services\DataMaintainanceBackgroundService.cs" />
<Compile Include="Services\Migration\BGTaskMigrator.cs" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\Contents.json">
Expand Down
43 changes: 43 additions & 0 deletions Covid19Radar/Covid19Radar.iOS/Services/Migration/BGTaskMigrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Threading.Tasks;
using BackgroundTasks;
using Covid19Radar.Services.Logs;
using Xamarin.Essentials;

namespace Covid19Radar.iOS.Services.Migration
{
internal class BGTaskMigrator
{
// Array of old identifier.
private static readonly string[] OLD_IDENTIFIER_ARRAY = {
AppInfo.PackageName + ".delete-old-logs",
};

private readonly ILoggerService _loggerService;

public BGTaskMigrator(
ILoggerService loggerService
)
{
_loggerService = loggerService;
}

internal Task ExecuteAsync()
{
_loggerService.StartMethod();

foreach (var identifier in OLD_IDENTIFIER_ARRAY)
{
BGTaskScheduler.Shared.Cancel(identifier);
_loggerService.Info($"BGTask {identifier} has been canceled.");
}

_loggerService.EndMethod();

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using Covid19Radar.Services.Logs;
using System.Threading.Tasks;
using Covid19Radar.Services.Migration;

namespace Covid19Radar.iOS.Services.Migration
{
public class MigrationProcessService : IMigrationProcessService
{
// Currently, It is not needed that iOS platform specific migration process.
private readonly ILoggerService _loggerService;

public MigrationProcessService(
ILoggerService loggerService
)
{
_loggerService = loggerService;
}

public async Task SetupAsync()
{
_loggerService.StartMethod();

await new BGTaskMigrator(
_loggerService
).ExecuteAsync();

_loggerService.EndMethod();
}
}
}