内容可用的静默通知未调用正确的AppDelegate方法

问题描述 投票:0回答:1

我已经添加了一些登录功能,该功能可以使用可用的内容通知向我们的应用下载相当大的内容包,并且我注意到有些行为有些奇怪,并且不确定如何正确处理:] >

  1. [据我所知,当应用程序长时间处于后台状态时,如果收到通知,则正确调用了application:didReceiveRemoteNotification:fetchCompletionHandler方法。
  2. 偶尔(尚待解决,但似乎是在离开应用程序后的某个时间),而不是调用上述方法,而是在后台启动应用程序,并使用remoteNotification键调用应用程序didFinishLaunchingWithOptions: ,并且永远不会调用上述方法。
  3. 方案2是这里的预期行为吗?我在网上看不到任何地方(苹果论坛,文档,官方网站)说这可能发生,但显然是这样!

如果发生2.,我的计划是检测该通知是否为无内容可用的通知,并像下面这样运行相同的后台下载逻辑(伪代码):

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的会话

INCORRECT

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

CORRECT

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.

我已经添加了一些登录功能,可以使用可用的内容通知将大量内容包下载到我们的应用程序中,并且我注意到某些行为有些奇怪,并且不是...

ios networking apple-push-notifications
1个回答
0
投票
[Paul的评论是正确的,这是预期的行为,如果在收到content-available通知之前由于某种原因终止了应用程序,则会调用didFinishLaunching方法。
© www.soinside.com 2019 - 2024. All rights reserved.