Доступное содержимое молчаливое уведомление не вызывает правильный метод AppDelegate - PullRequest
0 голосов
/ 03 апреля 2020

Я добавил некоторые возможности входа в систему для загрузки довольно больших комплектов контента с использованием уведомлений о доступном контенте в наше приложение, и я заметил некоторое поведение, которое немного странно, и не уверен, как правильно его обрабатывать:

  1. Если уведомление получено, когда приложение долгое время находилось в фоновом режиме, насколько я вижу, правильно вызывается метод application:didReceiveRemoteNotification:fetchCompletionHandler.
  2. Иногда (пока чтобы работать, когда это так, но, кажется, это может быть в течение определенного времени после выхода из приложения) вместо вызываемого выше метода, приложение запускается в фоновом режиме и приложение: didFinishLaunchingWithOptions вызывается с ключом remoteNotification, а метод выше никогда не вызывается.

Является ли сценарий 2. здесь ожидаемым поведением? Я не вижу нигде в Интернете (форумы Apple, документы, SO), говорящих, что это может произойти, но это очевидно!

Если 2. произойдет, я планирую определить, было ли уведомление молчаливым контентом. доступны уведомления и запустить тот же фон загрузки логики c (псевдокод), например, так:

var launchedByContentPush: Bool = false
if let remoteNotification = launchOptions?[.remoteNotification] as? [AnyHashable : Any], let aps = remoteNotification["aps"] as? [AnyHashable : Any] {
    launchedByContentPush = aps.keys.count == 1 && aps["content-available"] as? Int == 1
}

if launchedByContentPush {
 // 1. Don't do normal app-setup stuff which shouldn't be done
 // 2. Download content
}

Это разумный план, или я мог в конечном итоге сломать вещи под 1. в некоторых случаях пользователь на самом деле запускает приложение?

Просто на 100% подтверждаю: я получаю уведомления о доступном контенте, все работает на этом фронте, так что, насколько я знаю, это не проблема конфигурации!

Показаны некоторые журналы, один из сеансов, который работал безупречно, а другой - для сеанса, где applicationDidFinishLaunching называется

НЕПРАВИЛЬНО

2020-04-02T19:01:03Z [INFO] | com.threesidedcube.ThunderCloud (ContentController) | Initialising Content Controller
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Setting app build date to 2 April 2020 at 19:42:56
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | <REDACTED>
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T19:01:03Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | application:DidFinishLaunchingWithOptions with keys: [__C.UIApplicationLaunchOptionsKey(_rawValue: UIApplicationLaunchOptionsRemoteNotificationKey)]
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | `appLaunched` called
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking for app upgrade
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Optionally checking for updated content
2020-04-02T19:01:03Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking for updates with timestamp: 1585848393.0
2020-04-02T19:05:48Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationWillEnterForeground
2020-04-02T19:05:48Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking for updates failed: The request timed out.
2020-04-02T19:05:49Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationDidBecomeActive
2020-04-02T19:08:33Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationWillResignActive
2020-04-02T19:08:34Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationDidEnterBackground

ПРАВИЛЬНО

2020-04-02T23:19:12Z [INFO] | com.threesidedcube.ThunderCloud (ContentController) | Initialising Content Controller
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Setting app build date to 2 April 2020 at 19:42:56
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Base URL configured as: <REDACTED>
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:19:12Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | application:DidFinishLaunchingWithOptions with keys: []
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | `appLaunched` called
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking for app upgrade
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Optionally checking for updated content
2020-04-02T23:19:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking for updates with timestamp: 1585848393.0
2020-04-02T23:19:12Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationDidBecomeActive
2020-04-02T23:19:13Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No update found
2020-04-02T23:20:36Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationWillResignActive
2020-04-02T23:20:37Z [INFO] | com.threesidedcube.ThunderCloud (AppState) | applicationDidEnterBackground
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Push notification received, checking if it's a `content-available` push
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | content-available == 1 sending notification off to `ContentController`
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | `appLaunched` called
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking for app upgrade
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Handling content-available notification
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Making sure notification bundle isn't after a landmark publish this app shouldn't receive
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No landmark timestamp provided in notification
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Checking notification timestamp against latest on-disk bundle version
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Downloading content-available bundle with timestamp: 1685827838.0
2020-04-02T23:35:57Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Downloading bundle: <REDACTED>
Destination: file:///var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application%20Support/StormDeltaBundle/
2020-04-02T23:36:04Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Handling events for background url session: 784B47D4-C2B6-4310-ADD5-8539BE40A447-60638-000035ACB72C6167
2020-04-02T23:36:04Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Starting background request controller
2020-04-02T23:36:06Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Unpacking bundle...
2020-04-02T23:36:06Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | data.tar.gz read to data object
2020-04-02T23:36:06Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Attempting to gunzip data from data.tar.gz
2020-04-02T23:36:07Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Gunzip successful
2020-04-02T23:36:09Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Bundle tar saved to disk
2020-04-02T23:36:09Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Attempting to untar the bundle
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Untar successful
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Verifying bundle...
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Loading manifest.json into JSON object
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Loading manifest.json as dictionary
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | app.json exists
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | manifest.json exists
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Verifying pages
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Verifying languages
2020-04-02T23:36:12Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Verifying content
2020-04-02T23:36:13Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Bundle is valid
2020-04-02T23:36:13Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Cleaning up `data.tar.gz` and `data.tar` files
2020-04-02T23:36:13Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Copying bundle
From: file:///private/var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/tmp/StormDeltaBundle/
To: file:///var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application%20Support/StormDeltaBundle/
2020-04-02T23:36:26Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Beginning excluding from backup files in directory: /var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application Support/StormDeltaBundle/content
2020-04-02T23:36:29Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Beginning excluding from backup files in directory: /var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application Support/StormDeltaBundle/languages
2020-04-02T23:36:29Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Beginning excluding from backup files in directory: /var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application Support/StormDeltaBundle/data
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Beginning excluding from backup files in directory: /var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application Support/StormDeltaBundle/pages
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Beginning excluding from backup files in directory: /var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/Library/Application Support/StormDeltaBundle
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Removing bundle in directory: file:///private/var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/tmp/StormDeltaBundle/
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Update complete, Refreshing language
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: languages
Error: The folder “languages” doesn’t exist.
2020-04-02T23:36:31Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | Removing bundle in directory: file:///private/var/mobile/Containers/Data/Application/CBCB1B36-D853-4E36-B766-9F3F31158DF7/tmp/StormDeltaBundle/
2020-04-02T23:36:33Z [DEBUG] | com.threesidedcube.ThunderCloud (ContentController) | No files exist in streamed bundle directory subfolder: pages
Error: The folder “pages” doesn’t exist.

1 Ответ

0 голосов
/ 05 мая 2020

Комментарий Павла выше верен, это ожидаемое поведение, при котором метод didFinishLaunching будет вызываться, если приложение по какой-либо причине было прекращено до получения уведомления content-available.

...