iOS - 在设备设置中,如果我更改时间,即使在应用程序后台、终止状态下,它也应该得到通知

iOS - in device settings if i change time it should get notified even in app background, killed state

要获取设备设置时间更改通知,我发现我们必须使用 UIApplication.significantTimeChangeNotification 通知和 func applicationSignificantTimeChange(_ application: UIApplication) 委托方法。

但在我的情况下,即使应用程序处于后台或处于终止状态,我也必须向用户显示本地通知,说明设备时间已更改。可以吗,如果我们对此有任何解决方案,请告诉我。

我不相信。 iOS 无法向非 运行 的应用发送通知,并且它们不会在任何地方排队。

然而,一个潜在的解决方法是从可信的在线来源获取当前的 UTC 值,并将其与设备认为的 UTC 值进行比较并存储该偏移量。一旦您的应用程序重新启动,再次计算此偏移量,如果它与您之前存储的偏移量有显着差异,请采取您将采取的措施来响应重大时间更改通知。

来自 applicationSignificantTimeChange

上的 Apple 文档

If your app is currently suspended, this message is queued until your app returns to the foreground, at which point it is delivered. If multiple time changes occur, only the most recent one is delivered.

因此,它清楚地表明这仅在应用程序处于前台时才有效。当应用程序不是 运行 时,它甚至不会排队。

要在应用程序未运行时显示任何本地通知 运行,应将其安排在过去以便将来触发。并且当不是运行时,应用程序是不可能知道时间变化事件的。看起来你将无法实现你所要求的。